I am using SSMS 2012 and wanting to do something like this:
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
The logic was created so that way I should technically only build T3 once, but I keep getting error saying ##T3 cannot be created because it already exists. Even if count(*) from T1 >0. It's like it's still creating the table from the first if statement.
I have also tried this:
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