Re-use aliased field in SQL SELECT STATEMENT

Posted by Bad Display Name on Stack Overflow See other posts from Stack Overflow or by Bad Display Name
Published on 2010-03-15T11:54:56Z Indexed on 2010/03/15 11:59 UTC
Read the original article Hit count: 177

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about sql

Related posts about select