Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using a label from AS in a WHERE clause

Author  Topic 

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2012-08-22 : 07:59:23
I'm trying to use the label defined using AS in a WHERE clause. Is there any way to do that? This says "Invalid Column Name 'EmpStatus'".
This is a simplified version of the query.

select
case when New=1 then 'New Employee' when New=0 then 'Old Employee'
else 'Employee' end As EmpStatus
from Person

where EmpStatus like '%'

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-22 : 08:13:26
[code]select *
from
(
select case when New=1 then 'New Employee'
when New=0 then 'Old Employee'
else 'Employee' end As EmpStatus
from Person
) as D
where EmpStatus like '%'[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2012-08-22 : 08:38:58
Thank you. That worked. I wouldn't have figured this out myself.
Go to Top of Page
   

- Advertisement -