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 |
if Price=100 then Rate=.05 |
|
> |
Greater than |
if Price>100 then Rate=.05 |
|
< |
Less than |
if Price<100 then Rate=.05 |
|
<> |
Not equal |
if Price<>100 then Rate=.05 |
|
>= |
Greater than or equal |
if Price>=100 then Rate=.05 |
|
<= |
Less than or equal |
if Price<=100 then Rate=.05 |
|
NOT |
Logical negation |
if NOT Price=100 then Rate=.05 |
|
AND |
Logical and |
if Tax>3 AND Ship <5 then |
|
OR |
Logical or |
if Tax>3 OR Ship<5 then |
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 2 3 4 5 6 7 |
City1 = "Austin" City2 = "AUSTIN" IF City1 = City2 ... // Returns FALSE City1 = "Austin" City2 = "AUSTIN" 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 2 3 |
City1 = "Austin" City2 = "Austin " 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 2 3 4 |
boolean d, e = TRUE, f SetNull(f) d = e and f // d is NULL d = e or f // d is TRUE |