Relational operators

Relational operators perform relational comparisons in Boolean expressions – = and == (equal to), <> and != (not equal to), < (less than), > (more than), <= (less than or equal to), and >= (more than or equal to):

Description: Relational%20Operators2

 

Expressions with relational operators return TRUE or FALSE.

For example,

(22+8)/3 = 15 – returns FALSE

5 <= 10 – returns TRUE

"Tom" = "Dom" – returns FALSE

 

For numeric expressions, results of relational comparisons reflect relative positions for the calculated values of the two operands on the real line.

 

For character expressions, results depend on the position of the initial character of each operand in the collation sequence.

Collation sequence is a code-set order or a localized collation sequence in the COLLATION category defined in the locale files. If initial characters are identical in both strings, 4GL compares subsequent characters until it finds a non-identical character or the end of the string.

 

Relational comparisons in time expressions follow these rules:

  1. a < b is TRUE when a is a briefer interval span than b or when a is an earlier DATE or DATETIME value than b.
  2. a > b is TRUE when a is a longer interval span than b or when a is a later DATE or DATETIME value than b.
  3. You cannot compare INTERVAL values to a DATE or DATETIME value but you can compare DATE or DATETIME values with each other.

TRUE with relational operators

The value of the built-in constant TRUE is 1.

Boolean expressions like this return FALSE unless b is exactly equal to 1:

IF (b = TRUE) THEN ...

To determine whether any value is not zero or null, avoid using TRUE in Boolean comparisons. It is better to use such expressions as:

IF (b) THEN ...

IF (b IS NULL) THEN ...

Your code might be easier to read and might produce better results if you avoid using TRUE as an operand for ==, =, !=, and <>.

Data type compatibility

In general, you can compare numbers with numbers, character strings with character strings, and time values with time values.

You might get unexpected results if you use relational operators with expressions of non-similar data types.

For example, you cannot compare a span of time (an INTERVAL value) with a point in time (a DATE or DATETIME value). If a time operand of a boolean expression is of the INTERVAL data type, you can use relational operators to compare it only to an INTERVAL value.

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.