#tmporigin , . .
insert into resulttable
select
o.id,
case a.n when 1 then b1 when 2 then b2 else b3 end,
case a.n when 1 then c when 2 then e else g end
from
cross join (select 1n union all select 2 union all select 3) a
, CTE union, CTE 3
;WITH CTE AS (
)
select id,b1,c from CTE
union all
select id,b2,e from CTE
union all
select id,b3,g from CTE
. , CTE, , , .
, 3 "b" (), , b , - SQL Server CTE .
, , ( ), , CTE 3 ! ( --- BELOW HERE --- ABOVE HERE original query, .
if object_id('tempdb..
;
create table
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
insert
;with cte as (
select id.id, b1, b1.v c, b2, b2.v e, b3, b3.v g
from
(select distinct id, 2 as b1, 3 as b2, 7 as b3 from
left join
left join
left join
)
select b1, c from cte
union all
select b2, e from cte
union all
select b3, g from cte
order by b1
temp, union all.