SQL/MP Reference Manual
HP NonStop SQL/MP Reference Manual—523352-013
C-2
CASE Expression
CASE Expression
The CASE expression is a conditional expression. SQL evaluates the conditions in the
CASE expression and sets the CASE expression to a value based on the condition
that is true. If none of the search conditions are true, SQL sets the CASE expression to
the value specified in the ELSE clause or, if ELSE is not specified, SQL sets the CASE
expression to NULL.
search-condition-1 through search-condition-n
specifies a condition to test for. If the condition is true, the CASE expression
returns the associated result value. If no search-condition is true, the CASE
expression returns the value of the ELSE clause, or NULL if ELSE is not specified.
result-1 through result-n
specifies the result value (or NULL) associated with a specific search condition. All
the results specified in the CASE expression should have the same or comparable
data types.
result-x
specifies the value returned if none of the search conditions are true. If the ELSE
result-x clause is not specified, the CASE expression returns NULL if none of
the search conditions are true. The data type of result-x should be the same or
comparable to those of result-1 through result-n.
CASE
WHEN search-condition-1 THEN { result-1 | NULL }
WHEN search-condition-2 THEN { result-2 | NULL }
WHEN search-condition-3 THEN { result-3 | NULL }
. . .
WHEN search-condition-n THEN { result-n | NULL }
[ { ELSE result-x | NULL } ]
END
or
CASE target-value
WHEN value-1 THEN { result-1 | NULL }
WHEN value-2 THEN { result-2 | NULL }
WHEN value-3 THEN { result-3 | NULL }
. . .
WHEN value-n THEN { result-n | NULL }
[ { ELSE result-x | NULL } ]
END