April 29, 2005 at 9:32 pm
If you truly need to use positive logic (IS NULL instead of IS NOT NULL) and you also want to check for a zero value, the NULLIF function does a nice job...
IF NULLIF(OBJECT_ID('TempDB..##tablename'),0) IS NULL
BEGIN
yada...yada...
END
Checking for the temporary table name in SYSOBJECTS of the current database won't work because temp tables live in 'TempDB'.
Checking for the temporary table name in SYSOBJECTS of the TempDB database won't work because temp table names actually consist of the temp table name and a unique ID separated by enough underscores to make the whole temp table name 128 bytes long. And, the unique ID is not easy to predict and is not worth the time to do so.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing post 16 (of 15 total)
You must be logged in to reply to this topic. Login to reply