I am running a big query that creates a lot of temp tables. For each one, I put
if object_id('tempdb..##TempTable1') is not null
drop table ##TempTable1;
at the very beginning before I "select" variables "into" the temp table. But sometimes I still got error message that says "##TempTable1" already exists. This seems kind of random; it happens to some other temp tables as well. Why would this problem happen? Is there a better way to avoid this issue?