I have a case expression in a DB2 statement like the following.
SELECT A,
CASE WHEN B LIKE ' %'
THEN C
ELSE B
END CASE,
D
FROM TAB
I’d like to name the column that the case expression results in, but I get a syntax error with both the AS immediately following END CASE and by wrapping the entire expression in parentheses and following that with an AS.
Adding the AS (without the parens) results in the following error
199: SQL0199N The use of the reserved word “AS” following “” is not valid. Expected tokens may include: “, FROM INTO”. SQLSTATE=42601
How can I name this column?
The ending keyword is not
END CASE, it’s justEND:Here’s the documentation for CASE expression in DB2 – although it’s not needed really, that’s standard SQL.