version 11
case_expression
Description
A case_expression is used to apply one or more conditions when selecting an expression.
They can be used as follows, for example:
CASE
WHEN search_condition THEN arithmetic_expression
...
WHEN search_condition THEN arithmetic_expression
[ELSE arithmetic_expression]
END
Or:
CASE arithmetic_expression
WHEN arithmetic_expression THEN arithmetic_expression
...
WHEN arithmetic_expression THEN arithmetic_expression
[ELSE arithmetic_expression]
END
Example
This example selects records from the ROOM_NUMBER column according to the value of the ROOM_FLOOR column:
SELECT ROOM_NUMBER CASE ROOM_FLOOR WHEN 'Ground floor' THEN 0 WHEN 'First floor' THEN 1 WHEN 'Second floor' THEN 2 END AS FLOORS, SLEEPING_ROOM FROM T_ROOMS ORDER BY FLOORS, SLEEPING_ROOM
See Also
arithmetic_expression, search_condition.