Skip to content
Advertisement

How use case statement alias in where clause

I’m trying to use a case statement and the results to in an alias, but I need to use the alias in my where clause and this doesn’t seem to be working. How do I use the alias (isPrimary below) in my where clause. See comment where I’m trying to use isPrimary in my where clause, which doesn’t work. How do I use the alias in the where clause?

I was looking at [case alias where][1] but it doesn’t try to use the alias in the where clause. I don’t see how to do that in my search. I need to return the null “types” that aren’t primary. There are multiple cases, not just the one in the services table.

Advertisement

Answer

You could do your initial query as a CTE to get the alias and then use your WHERE condition on that resulting data set.

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