Is it possible to alias a column name and then use that in a CASE statement? For example,
SELECT col1 as a, CASE WHEN a = \'test\' THEN \'yes\' END as value
Nor in MsSql
SELECT col1 AS o, e = CASE WHEN o < GETDATE() THEN o ELSE GETDATE() END FROM Table1
Returns:
Msg 207, Level 16, State 3, Line 1 Invalid column name 'o'. Msg 207, Level 16, State 3, Line 1 Invalid column name 'o'.
However if I change to CASE WHEN col1... THEN col1 it works