Convert???

Post Reply
MiniMe
Posts: 210
Joined: Thu Mar 15, 2001 4:30 pm

Convert???

Post by MiniMe »

I have a snippet of code that looks like this:

<sql ROW "delete from tempadds">

Processing $BN for $Userid / $UsRec
<sum "%s
" $Userid $UsRec>
<$useridrec = $ret>
<SQL MAX = '1' "select * from books where USER_ID\USER_REC= $ret"></sql>

Problem is when the both variables have a strictly numeric value the sum statement does funky things and turns it something I dont want as seen below:

<!-- 200 runaddsV2:9: delete from tempadds; -->
Processing 8032087068 for 53021449 / 03799
5.30252e+07

<!-- 200 runaddsV2:15: select * from books where USER_ID\USER_REC= `5.30252e+07.'; -->
Record not found - Inserting


How can I get the desired output from the sum??

M.
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Convert???

Post by John »

You might use strfmt in that case, e.g. <strfmt "%s\n%s" $Userid $UsRec>, however it looks as if it would make sense to do the query:

<SQL MAX = '1' "select * from books where USER_ID = $Userid and USER_REC = $UsRec">

and have an index on books(USER_ID, USER_REC)
John Turnbull
Thunderstone Software
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Convert???

Post by mark »

It's doing a numeric sum then presenting it in string form. To force a string sum (concatenation) include an empty string:

<sum "%s
" "" $Userid $UsRec><substr $ret 1 -1>

or use strfmt

<strfmt "%s\x0a%s" $Userid $UsRec>
MiniMe
Posts: 210
Joined: Thu Mar 15, 2001 4:30 pm

Convert???

Post by MiniMe »

I ended up using this method...

<sum "%s
" "" $Userid $UsRec><substr $ret 1 -1>


The first idea of doing a it in two indexes was slower than the way were doing it and for some reason the
<strfmt "%s\x0a%s" $Userid $UsRec>

method was causing sporadic results.

Thanks
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Convert???

Post by John »

I wasn't suggesting two indexes, but a single index on two fields. Using two separate indexes would be slower.
John Turnbull
Thunderstone Software
MiniMe
Posts: 210
Joined: Thu Mar 15, 2001 4:30 pm

Convert???

Post by MiniMe »

Oh.. sorry.. I wasnt aware you could do it that way. I guess I need to keep up with enhancemenets.
Post Reply