IF
Purpose
The IF THEN ELSE syntax is an alternate to CASE function.
Syntax
if::=
Usage Notes
- If the condition evaluates to true, the expression after
THENis returned. - If the condition evaluates to false, the expression after
ELSEis returned, orNULLif anELSEexpression is not defined. - If the condition evaluates to
NULL/UNKNOWN, the expression returnsNULL.
Examples
SELECT name, age, IF age < 18 THEN 'underaged' ELSE 'adult' ENDIF AS 'LEGALITY' FROM persons;
Result
| NAME | AGE | LEGALITY |
| Alice | 25 | adult |
| Bob | 16 | underaged |
| Charlie | NULL | NULL |
| David | 34 | adult |