Previous Topic: Multiple WITH ClausesNext Topic: SQL Statements


Evaluation of Logical Expressions

CA Dataquery evaluates logical expressions in the following order:

  1. Expressions contained within parentheses
  2. Expressions within parentheses preceded by NOT
  3. Expressions joined with AND
  4. Expressions joined with OR

The following chart illustrates how CA Dataquery evaluates logical expressions which contain parentheses or NOT.

Example and Explanation

EXPR1 AND EXPR2 AND EXPR3

CA Dataquery selects only those rows which meet the criteria specified in all three expressions.

EXPR1 AND (EXPR2 OR EXPR3)

CA Dataquery selects only those rows which meet the criteria in EXPR1 and the criteria in either EXPR2 or EXPR3.

(EXPR1 AND EXPR2) OR EXPR3

CA Dataquery selects only those rows which meet the criteria stated in both EXPR1 and EXPR2 or just the criteria stated in EXPR3.

NOT (EXPR1 AND EXPR2) AND EXPR3

CA Dataquery selects only those rows which do not meet the criteria specified in either EXPR1 or EXPR2, but do meet the criteria in EXPR3.

If you do not use parentheses to group your logical expressions, CA Dataquery will evaluate expressions joined by AND first. For example,

EXPR1 AND EXPR2 OR EXPR3

is equivalent to

(EXPR1 AND EXPR2) OR EXPR3