Monday, June 30, 2014

sql query

Try



select 10 Projectid , 1 status into #temp1 union all
select 10 , 0 union all
select 11 ,0 union all
select 12 , 1 union all
select 13 ,0

select isnull(a.Projectid,b.Projectid), case
when a.status =0 and b.status =1 then 2
when a.status =0 and b.status is null then 1
when b.status =1 and a.status is null then 0
else null end
from
(select * from #temp1 where status = 0)a
full outer join
(select * from #temp1 where status = 1)b
on a.Projectid=b.Projectid
order by 1

Thanks


Saravana Kumar C


No comments:

Post a Comment