Relational operators in PowerBuilder
Description
PowerBuilder uses relational operators in boolean expressions
to evaluate two or more operands. Logical operators can join relational
expressions to form more complex boolean expressions.
The result of evaluating a boolean expression is always true or false.
The following table lists relational and logical operators.
|
Operator |
Meaning |
Example |
|---|---|---|
|
= |
Equals |
|
|
> |
Greater than |
|
|
< |
Less than |
|
|
<> |
Not equal |
|
|
>= |
Greater than or equal |
|
|
<= |
Less than or equal |
|
|
NOT |
Logical negation |
|
|
AND |
Logical and |
|
|
OR |
Logical or |
|
Usage
Comparing strings
When PowerBuilder compares strings, the comparison is case
sensitive. Trailing blanks are significant.
For information on comparing strings regardless
of case, see the functions Upper and Lower.
To remove trailing blanks, use the RightTrim function.
To remove leading blanks, use the LeftTrim function.
To remove leading and trailing blanks, use the Trim function.
For information about these functions, see RightTrim, LeftTrim,
and Trim.
Decimal operands
Relational operators that operate on numeric values (including =, >, <, <>, >=,
and <=) can take decimal operands. The precision of
the decimal operand is maintained in comparisons.
Null value evaluations
When you form a boolean expression that contains a null value,
the AND and OR operators behave
differently. Thinking of null as undefined (neither true nor false)
makes the results easier to calculate.
For more information about null values,
see “NULL values “.
Examples
Case-sensitive comparisons
If you compare two strings with the same text but different
case, the comparison fails. But if you use the Upper or Lower function,
you can ensure that the case of both strings are the same so that
only the content affects the comparison:
|
1 |
City1 = "Austin" |
|
1 |
City2 = "AUSTIN" |
|
1 |
IF City1 = City2 ... // Returns FALSE |
|
1 |
|
1 |
City1 = "Austin" |
|
1 |
City2 = "AUSTIN" |
|
1 |
IF Upper(City1) = Upper(City2)... // Returns TRUE |
Trailing blanks in comparisons
In this example, trailing blanks in one string cause the comparison
to fail:
|
1 |
City1 = "Austin" |
|
1 |
City2 = "Austin " |
|
1 |
IF City1 = City2 ... // Returns FALSE |
Logical expressions with null values
In this example, the expressions involving the variable f,
which has been set to null, have null values:
|
1 |
boolean d, e = TRUE, f |
|
1 |
SetNull(f) |
|
1 |
d = e and f // d is NULL |
|
1 |
d = e or f // d is TRUE |