IF Expressions

The IF expression provides IF-THEN-ELSE SQL expressions.

The syntax of the IF expression is as follows:

IF condition 
THEN expression1ELSE expression2 ] 
ENDIF

This expression returns:

  • If condition is TRUE, the IF expression returns expression1.

  • If condition is FALSE, the IF expression returns expression2.

  • If condition is FALSE, and there is no expression2, the IF expression returns NULL.

  • If condition is NULL, the IF expression returns NULL.

Note: IF statement is different from IF expression.

Do not confuse the syntax of the IF expression with that of the IF statement.

Related concepts
Constants in Expressions
Column Names in Expressions
Subqueries in Expressions
SQL Operators
Compatibility of Expressions and Constants
Related reference
CASE Expressions