Skip to content
Advertisement

Access alias in CASE statement

I am trying to create a column called DateStartedStatus that utilizes a previously aliased column to compute its value. It should use CurrentStatus to output a value and an error is showing that says “Invalid column name ‘CurrentStatus'”. How can I access that alias in the below case statement?

Advertisement

Answer

Using subqueries like this

Do not worry, subquery will not add computational complexity, optimizer will remove it if possible.

Another way is nested CASE expressions (query is not readable):

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement