Re-use aliased field in SQL SELECT STATEMENT
- by Bad Display Name
Hi, the question is hard to define without giving an example, e.g. I'd like to achieve something like this
:
SELECT
(CASE WHEN ...) AS FieldA,
20 + FieldA AS FieldB
FROM Tbl
Assuming that by "..." I've replaced a long and complex CASE statement, hence I don't want to repeat it when selecting FieldB and use the aliased FieldA instead.
IS THIS EVEN POSSIBLE? What could be a workaround? Note, that this will return multiple rows , hence the DECLARE/SET outside the SELECT statement is no good in my case.
PLEASE HELP.
P.S. I am using SQL 2008