Sample Header Ad - 728x90

OBJECT_ID fails to find existing temp table

-1 votes
1 answer
117 views
I'm using temp tables to stage data before inserting into production. As a couple of things use them, before anything else I do a: IF OBJECT_ID(N'##Projects_TEMP') IS NOT NULL TRUNCATE TABLE ##Projects_TEMP ELSE SELECT * INTO ##Projects_TEMP FROM Projects WHERE 1=0 The idea is to clear the table if it's there, and make the table if it's not. I believe that T-SQL should do that? However: select OBJECT_ID(N'##Projects_TEMP') always returns NULL. This is surprising, because the table *does* exist in that connection (I did so manually in SSMS to be sure), and: select * from ##Projects_TEMP Works fine. What am I missing here?
Asked by Maury Markowitz (230 rep)
Dec 6, 2024, 05:52 PM
Last activity: Dec 6, 2024, 05:59 PM