April 21, 2009 at 4:23 pm
Hello,
I am writing a stored procedure and I use template tables.
I want to check if a template table exists. As you can tell, I am running the code over and over in optimizing. I have to drop the table and then run the real code.
I want to write an the code so that it checks for the existence of the table on its own.
I tried:
if OBJECT_ID('#TCompanyNames', 'U') is not null
print 'table exists'
else
print 'table does not exists'
It tells me the table does not exists.
However, I can still do (select * from #TcompanyNames) and will get rows returned.
Can someone please help?
Thanks.
Tony
Things will work out. Get back up, change some parameters and recode.
April 21, 2009 at 5:54 pm
Make sure to check for the table in the tempdb. The following code should work.
if OBJECT_ID('tempdb..#TCompanyNames', 'U') is not null
print 'table exists'
else
print 'table does not exists'
April 22, 2009 at 5:50 am
Thanks Ken
That worked! I knew it was something small that I was missiing. However, it was driving me crazy when I couldn't find the answer through the articles or in BOL.
Thanks again.
Tony
Things will work out. Get back up, change some parameters and recode.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply