我正在使用 SSMS 2012 并想做这样的事情:
If(Select count(*) from T1) > 0
Begin
Select * into ##T3 from T2
end
If(Select count(*) from T1) < 0
Begin
Select * into ##T3 from T4
end
创建了逻辑,因此从技术上讲,我应该只构建一次 T3,但我一直收到错误消息,说 ##T3 无法创建,因为它已经存在。即使来自 T1 的 count(*) > 0。就像它仍在从第一个 if 语句创建表一样。
我也试过这个:
If(Select count(*) from T1) > 0
Begin
IF OBJECT_ID('tempdb..##T3') is not null Drop Table ##T3
Select * into ##T3 from T2
end
If(Select count(*) from T1) < 0
Begin
IF OBJECT_ID('tempdb..##T3') is not null Drop Table ##T3
Select * into ##T3 from T4
end