Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 temp table already exists in database

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2010-06-03 : 12:49:40
I have:

select *
into #temptbl
from tbl

i get the following error

There is already an object named '#temptbl' in the database.

Im calling this in a stored procedure but was trying to test it in query window. why cant i make a temp table this way and not have it conflict?

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-06-03 : 13:07:38
You can create it. But as the error clearly states, there is already a table named #temptbl present. You will have to use a different name fo rthis temp table or drop the existing table before creating this.
Try adding this before your query.
IF OBJECT_ID('Tempdb.dbo.#temptbl', 'u') IS NOT NULL
DROP TABLE #temptbl
Go to Top of Page
   

- Advertisement -