Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
And and Or in one SQL Statement
Message
 
 
To
07/10/2004 09:25:40
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00949508
Message ID:
00949528
Views:
11
Steven,

Like you need ( ) in algebra to deal with operator precedence, you need to do the same with logical operators. AND has higher precedence than OR, just like * has higher precedence than +.

x and y or z && x, y get AND'd first, then that result is OR'd with z
x or y and z && y, z AND'd, that result is OR'd with x

To get OR evaluated before AND you have to use ( )

x and ( y or z ) && y, z OR'd, then that result is AND'd with x

Another thing that happens in VFP though is there a boolean expression optimizer that will stop evaluating the expression once VFP has a result that won't change. ie

x = .t.
y = .f.
z = .t.

x and y and z && a, y AND'd to a .F. result, because the next operator is AND VFP won't even evaluate z

x or y or z && only x is evaluated, since it's .T. none of the rest of the expression is evaluated.

>How can I create an SQL statement that gets all records of one field value and the true condition of a second field or a not empty of a third field?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform