Saturday, February 11, 2012

#temp table - Checking if it exists

Hi,
I'd like to check if a #temp table I created in a previous session still
resides on the DB.
I've used the following code and have had no luck
*************
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[#temp]'))
drop table #temp
Try:
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
Hope this helps.
Dan Guzman
SQL Server MVP
"Jacques Victor" <jacques@.ideosphere.co.za> wrote in message
news:%23I0cQMOOEHA.1616@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I'd like to check if a #temp table I created in a previous session still
> resides on the DB.
> I've used the following code and have had no luck
> *************
> IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[#temp]'))
> drop table #temp
>

No comments:

Post a Comment