Connecting Tech Pros Worldwide Help | Site Map

How do I detect a local temp table

  #1  
Old November 14th, 2008, 05:25 PM
Dom
Guest
 
Posts: n/a
I sometimes begin a script like this:

-------------------------------------------------------------
if exists (select * from sysobjects where name = 'T_Table') drop table
T_Table

select * into T_Table (etc)
-------------------------------------------------------------

How do I do this with a local temp table? I thought of this:

if exists (select * from sysobjects where name like '#Temp_%') drop
table #Temp

.... but that seems dangerous to me. Is there a better way?

Dom




  #2  
Old November 14th, 2008, 06:35 PM
Plamen Ratchev
Guest
 
Posts: n/a

re: How do I detect a local temp table


I normally use this approach which works well:

IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL
DROP TABLE #Temp;


--
Plamen Ratchev
http://www.SQLStudio.com
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access expoert reports to PDF using PDF writer 6.0 issues Grasshopper answers 11 November 13th, 2005 07:08 AM
How do I create pdf reports from Access? dog answers 7 November 13th, 2005 07:06 AM
Why must I use PrtDevMode Randy Harris answers 5 November 12th, 2005 04:11 PM
Temporary tables and miscellaneous schemas btober@seaworthysys.com answers 30 November 12th, 2005 12:35 AM