I’d like to achieve something like this:
SELECT
(CASE WHEN ...) AS FieldA,
FieldA + 20 AS FieldB
FROM Tbl
Assuming that by “…” I’ve replaced a long and complex CASE statement, I don’t want to repeat it when selecting FieldB and use the aliased FieldA instead.
Note, that this will return multiple rows, hence the DECLARE/SET outside the SELECT statement is no good in my case.
A workaroud would be to use a sub-query:
To improve readability you could also use a
CTE: