Hello pavan ,
Bellow i am giving one example You can make same changes
select * from(
select case departmentid when 9 then'A' when 6 then 'B' when 12 then 'c' end as [dpt], * from bugsmaster) bug where [dpt]='A'
Where you need to put your query inside select as bellow
Select * from (------)
Replace your query with ------ and use the same alias column for your where clause.
Cheers