declare @t1 table(c1 varchar(10),c2 varchar(10)) declare @t2 table(d1 varchar(10),c2 varchar(10),d2 varchar(10),d3 varchar(10))insert @t1 select 'aa','aa1' union all select 'bb','bb1'insert @t2 select 'dd','aa1','dd2','dd3' union all select 'ff','bb1','ff2','ff3' union all select 'gg','aa1','gg2','gg3' union all select 'hh','aa1','hh2','hh3'select c1 as y ,c2, null as d2 from @t1 union all select d1 as y ,c2,d2 from @t2---------------------------------- aa aa1 NULL bb bb1 NULL dd aa1 dd2 ff bb1 ff2 gg aa1 gg2 hh aa1 hh2
declare @t2 table(d1 varchar(10),c2 varchar(10),d2 varchar(10),d3 varchar(10))insert @t1
select 'aa','aa1' union all
select 'bb','bb1'insert @t2
select 'dd','aa1','dd2','dd3' union all
select 'ff','bb1','ff2','ff3' union all
select 'gg','aa1','gg2','gg3' union all
select 'hh','aa1','hh2','hh3'select c1 as y ,c2, null as d2 from @t1 union all
select d1 as y ,c2,d2 from @t2----------------------------------
aa aa1 NULL
bb bb1 NULL
dd aa1 dd2
ff bb1 ff2
gg aa1 gg2
hh aa1 hh2