Case
is a conditional SQL expression: It returns the value of that then
expression which follows the first true when
clause. If no when
condition is true, the value of the else
expression is returned or null
if there is no else
.
SELECT CASE WHEN x > 100 THEN 'too large'
ELSE 'ok'
END
FROM …
Tutorials
Other conditional expressions
Product specific features: if
, iif
, decode
.
The searched case
expression is defined in ISO/IEC 9075:2016-2 as mandatory feature F261-02.
You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Twitter or RSS to gradually catch up and to keep modern-sql.com on your radar.
The essence of SQL tuning in 200 pages
Buy now!
(paperback and/or PDF)
Paperback also available at Amazon.com.
Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »