# Relational Operators

Relational operators compare numeric, character string, or logical data. The result of the comparison, either true ( 1 ) or false ( 0 ), can be used to make a decision regarding program flow (see the IF statement). Table 1 lists the relational operators.

Table 1. Relational Operators
Operator Relation Example
EQ or = Equality X = Y
NE or # Inequality X # Y
>< or <> Inequality X <> Y
LT or < Less than X < Y
GT or > Greater than X > Y
LE or <= or =< or #> Less than or equal to X <= Y
GE or >= or => or #< Greater than or equal to X >= Y

When arithmetic and relational operators are both used in an expression, the arithmetic operations are performed first. For example, the expression:

``X + Y < (T - 1) / Z``

is true if the value of X plus Y is less than the value of T minus 1 divided by Z.

String comparisons are made by comparing the ASCII values of single characters from each string. The string with the higher numeric ASCII code equivalent is considered to be greater. If all the ASCII codes are the same, the strings are considered equal.

If the two strings have different lengths, but the shorter string is otherwise identical to the beginning of the longer string, the longer string is considered greater.

Note: An empty string is always compared as a character string. It does not equal numeric zero.

A space is evaluated as less than zero. Leading and trailing spaces are significant. If two strings can be converted to numeric, then the comparison is always made numerically.

Some examples of true comparisons are:

``````"AA" < "AB"
"FILENAME" = "FILENAME"
"X&" > "X#"
"CL  " > "CL"
"kg" > "KG"
"SMYTH" < "SMYTHE"
B\$ < "9/14/93"          (where B\$ = "8/14/93")``````

The results of any comparison involving the null value cannot be determined-that is, the result of using a relational operator to compare any value to the null value is unknown. You cannot test for the null value using the = (equal) operator, because the null value is not equal to any value, including itself. The only way to test for the null value is to use the function ISNULL function or ISNULLS function.