CASE value expressions allow derived column values in a target row to vary depending on which condition is satisfied by the corresponding source row. The CASE value expression has the same structure as the CASE DML expression, except that it associates a numeric value expression or string value expression with each condition rather than a DML group, as follows:
CASE WHEN <condition 1> THEN <value expression 1> WHEN <condition 2> THEN <value expression 2> : : : : WHEN <condition n> THEN <value expression n> ELSE <value expression n+1> END
The value of a CASE value expression is the value of the expression corresponding to the first condition that is met, else the value of the ELSE’s expression, if present, else NULL. The value expressions must all evaluate to data values of the same basic type, either all numeric or all string.
CASE Value Expression Example
SELECT COL1 CASE WHEN COL2 < 256 THEN COL4 * 16 WHEN COL2 > 32767 THEN COL4 + COL5 ELSE COL6 END AS COL2, COL3 FROM...