Case
is a conditional SQL expression : It returns the value of a different expression (formula in then
or else
branch) based on one or more conditions in the when
clause.
SELECT CASE WHEN column_name > 100 THEN 'too large'
ELSE 'ok'
END
FROM …
Tutorial: Case
— Conditional Expressions
Abbreviations: case … when …
(simple case), coalesce
, nullif
.
Product specific features: if
, iif
, decode
.
The searched case
expression is defined in ISO/IEC 9075:2016-2 as mandatory feature F261-02.
The essence of SQL tuning in 200 pages
Buy on Amazon
(paperback only)
Paperback and PDF also available at Markus’ store.
Markus offers SQL training and consulting for developers working at companies of any size.
Learn more »