select id, case id when 1 then 0 else 1 end as C1, case id when 2 then 0 else 1 end as C2, .... from #testt where C1 > 0 OR C2 > 0
declare @t table(id int) insert into @t select 1 union all select 2 union all select 3 select id, c1, c2 from @t cross apply (select case id when 1 then 0 else 1 end as c1 ,case id when 2 then 0 else 1 end as c2 ) as tt where c1 > 0 or c2 > 0 id c1 c2 ----------- ----------- ----------- 1 0 1 2 1 0 3 1 1 (3 row(s) affected)