在 sql 服务器中将所有与 #temptable 存在条件联合起来?
union all with #temptable exist condition in sql server?
我得到了
INSERT INTO TABLE3
SELECT * FROM table1
UNION ALL
if object_id('tempdb..#temp') is not null drop table tempdb..#temp
select * into #temp from (SELECT * FROM table2) then original SELECT for UNION
但我收到语法错误?
如有任何帮助,我们将不胜感激。谢谢
我不太确定你想要实现什么,但我认为它会帮助你在插入之前删除 table。
if object_id('tempdb..#temp') is not null
drop table tempdb..#temp
SELECT * INTO #temp
FROM table2
INSERT INTO TABLE3
SELECT *
FROM table1
UNION ALL
SELECT *
FROM #temp
我得到了
INSERT INTO TABLE3
SELECT * FROM table1
UNION ALL
if object_id('tempdb..#temp') is not null drop table tempdb..#temp
select * into #temp from (SELECT * FROM table2) then original SELECT for UNION
但我收到语法错误?
如有任何帮助,我们将不胜感激。谢谢
我不太确定你想要实现什么,但我认为它会帮助你在插入之前删除 table。
if object_id('tempdb..#temp') is not null
drop table tempdb..#temp
SELECT * INTO #temp
FROM table2
INSERT INTO TABLE3
SELECT *
FROM table1
UNION ALL
SELECT *
FROM #temp