两张表用union合并后如何放到临时表中

2024-12-18 15:55:48
推荐回答(2个)
回答1:

如果#temp已经建好了表:
insert into #temp select * from
(
select * from V_LW_YouhuiDetailByShenFenZheng
union all
select * from V_LW_YouhuiDetailByzhengjian
);
commit;

如果#temp还没有建:
create table #temp as select * from
(
select * from V_LW_YouhuiDetailByShenFenZheng
union all
select * from V_LW_YouhuiDetailByzhengjian
);

回答2:

select * into #temp from
(
select * from V_LW_YouhuiDetailByShenFenZheng
union all
select * from V_LW_YouhuiDetailByzhengjian
) a

加个别名就行了