Expression Overview with QrySelect

Estimated reading time: 3 minutes

An expression to be used with a QrySelect within DCLDISKFILE is a logical expression consisting of one or more relational expressions optionally combined with the “&” (and) and “ ” (or) operators. Since “&” has a higher priority than “ ”, you can use parentheses to force the order in which the expression is evaluated.

An expression is defined by a single or double quote, followed by any combination of characters, and terminated by a single or double quote. Note that a numeric field can be compared against numeric constants, and a character field must be compared against a quoted character constant .

Please note that if you want a double quote within a literal, you must include two quotes. For example, to assign to a character field the value <pre>He said “Come NOW!”.</pre>, The assignemnt would have to coded like this: <pre>phrase = “He said ““Come NOW!””.”</pre>

A relational expression consists of a field name, a relational operator and a constant or another field name.

The valid relational operators are:

< LT Less Than
> GT Great Than
<= LE Less Than or Equal To
>= GE Greater Than or Equal To
= EQ Equal Condition
!= NE Not Equal Condition
<> NE Not Equal Condition
& AND And
|, OR Or

The example below ( Table 1 ) lists some example expressions, showing that if you want the expression to equal a particular character value, you must put double quotes around the value. Note that you do not need to specify quotes around a numeric value.

The result of the expression is derived from the fields X, Y and Z as listed in table 2 below.

Table 1

Expression

Explanation Result
"x = y" The contents of field x = the contents of field y. Record 2
"x = ""y""" The contents of field x = the character value Y. Record 5
"Z = 4" The contents of field Z = the value 4. Record 4

Table 2

Field X

Field Y Field Z
A X 1
B B 2
C Y 3
X C 4
Y Z 5
Z A 6