Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
= and == in SQL
Message
 
To
27/03/2002 08:39:29
Denis Filer
University of Oxford
United Kingdom
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00637774
Message ID:
00638128
Views:
26
Denis,

This is related to how xBase compares strings, by default strings are compared until the string on the right of the comparison operator is exhausted and the result at that point is returned.

In VFP we can control this behavior using the SET EXACT and SET ANSI commands. SET EXACT works for Fox operations and SET ANSI works for SQL SELECT operations.

Both SET EXACT and SET ANSI work the same way, if they are OFF the comparison is to the end of the shorter string, if they are ON then the shorter string is padded with spaces to be equal in length to the longer string and then they are compared.

SET EXACT ON and SET ANSI ON are NOT the same as ==. == compares for exact equality. An example will illustrate the difference better than discussion.
SET EXACT ON
lcVar1 = "Jim"
lcVar2 = "Jimmy"
? lcVar2 = lcVar1  && .F.
? lcvar2 == lcvar1 && .F.
lcvar2 = "Jim   "
? lcVar2 = lcVar1  && .T. because the shorter is padded with spaces
? lcvar2 == lcvar1 && .F. because they are not the same length
Previous
Reply
Map
View

Click here to load this message in the networking platform