Friday, 8 February 2013

If exists , drop temp table

I have to write this code again and again, so keeping it here as a handy reference.


IF EXISTS( SELECT 1

FROM tempdb.dbo.sysobjects

where ID = OBJECT_ID(N'#tempOutput'))


BEGIN

DROP TABLE #tempOutput

END
------OR--------

IFOBJECT_ID(N'tempdb..#Temp') IS NOT NULL
BEGIN
DROP TABLE #Temp
END

No comments:

Post a Comment