Is there an ANSI SQL equivalent to Oracle's DECODE function?
Oracle's decode function is the IF-THEN-ELSE construct in SQL.
Is there an ANSI SQL equivalent to Oracle's DECODE function?
Oracle's decode function is the IF-THEN-ELSE construct in SQL.
CASE WHEN a=1 THEN value1
WHEN a=2 THEN value2
ELSE default
END
http://stackoverflow.com/questions/4622/sql-case-statement-syntax
A CASE expression is the ANSI SQL method, of which there are 2 varieties, "simple" and "searched":
1) Simple CASE expression:
CASE col WHEN 1 THEN 'One'
WHEN 2 THEN 'Two'
ELSE 'More'
END
2) Searched CASE expression:
CASE WHEN col < 0 THEN 'Negative'
WHEN col = 0 THEN 'Zero'
ELSE 'Positive'
END