>Here is an example of a command to create a temporary table:
>
>
>SELECT Numero INTO #Temp FROM Country WHERE Country.Numero<10
>
>
>That will create #Temp with 9 records.
>
>If I try to do this again, I have:
>
>"There is already an object named '#Temp' in the database."
>
>However, this does not exist in the database. This is memory only.
>
>So, for as long as I remain in the same window, I cannot do it. But, if I open another query window, I can do this command again.
>
>What kind of cleanup is necessary so I can execute the same command?
IF OBJECT_ID('TempDB..#Temp', N'U') IS NOT NULL DROP TABLE #Temp;
select numero into #Temp from dbo.Country where Country.Numero < 10;
The first check with object_id will verify if the table already exists or not and will drop it if it exists.
If it's not broken, fix it until it is.
My Blog