Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Doing Comparisons against fields in a record set.


Message #1 by "Richard Basel" <rbasel@h...> on Mon, 26 Mar 2001 21:46:11
I am trying to do comparisons against fields returned in a record set, 

with mixed results.  Numeric comparisons seem to work fine.  Its when I 

try to compare a field to a string where I have problems.



I have tried converting to strings.  Using variables to hold the value 

returned by the record and just about anything else I could think of.



_____________________________________________________



Here is the test code I have written



dim test123

dim test456

dim test567

dim test789



test456 = "test"

test567 = "test"



if test456 = test567 then 

response.write "yes" & "<BR>"

else

response.write "no" & "<BR>"

end if 



test123 = RSMAIFFees("comm_type")

Response.Write "test123  type = " & TypeName(test123) & "<BR>"

Response.Write "RSMAIFFees(comm_type) type = " & TypeName(RSMAIFFees

("comm_type")) & "<BR>"

Response.Write "cstr(RSMAIFFees(comm_type)) type = " & TypeName( cstr

(RSMAIFFees("comm_type"))) & "<BR>"



response.write test123  & "<BR>"

response.write RSMAIFFees("comm_type")  & "<BR>"



test789 = "GROSS"

		

If test123 = test789 then 

response.write "i got it <BR>"

else 

	response.write "i dont have it" & "<BR>"

end if

	

________________________________________________



and here is the output



yes

test123 type = String

RSMAIFFees(comm_type) type = Field

cstr(RSMAIFFees(comm_type)) type = String

GROSS 

GROSS 

i dont have it



_____________________



As far as I can see the comparison of  test456 = test567 and the 

comparison of test123 = test789 should be identical.  Yet one evaluates to 

true while the other evaluates to false.

Message #2 by "Ken Schaefer" <ken@a...> on Tue, 27 Mar 2001 17:59:11 +1000

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

: and here is the output

:

: yes

: test123 type = String

: RSMAIFFees(comm_type) type = Field

: cstr(RSMAIFFees(comm_type)) type = String

: GROSS

: GROSS

: i dont have it

:

: _____________________

:

: As far as I can see the comparison of  test456 = test567 and the

: comparison of test123 = test789 should be identical.  Yet one evaluates to

: true while the other evaluates to false.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Possibly there are spaces in the field from your database. Did you try to

Trim() the value from the DB?



If CStr(Trim(test123)) = CStr(Trim(test789)) then

    Response.Write("I got it")

Else

    Response.Write("I don't have it")

End if



Alternatively, try LenB() on each string to make sure they are composed of

the same binary characters, and that there aren't any non-printing ASCII

chars tacked onto the end of the value from your DB...



HTH



Cheers

Ken



Message #3 by "Richard Basel" <rbasel@h...> on Tue, 27 Mar 2001 17:04:38
That was the problem exactly.  Now I can put a Band-Aid on my forehead 

where I was banging it against my desk and continue with the development. 



Thanks for your help.



> 

> Possibly there are spaces in the field from your database. Did you try to

> Trim() the value from the DB?

> 

> If CStr(Trim(test123)) = CStr(Trim(test789)) then

>     Response.Write("I got it")

> Else

>     Response.Write("I don't have it")

> End if

> 

> Alternatively, try LenB() on each string to make sure they are composed 

of

> the same binary characters, and that there aren't any non-printing ASCII

> chars tacked onto the end of the value from your DB...

> 

> HTH

> 

> Cheers

> Ken

> 


  Return to Index