Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to find a temporary table?

Author  Topic 

Wodzu
Yak Posting Veteran

58 Posts

Posted - 2008-02-04 : 04:27:55
Hello folks. I am having problem with finding a temporary table.

Here is an example:

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[##tmpTable]'))
BEGIN
DROP TABLE dbo.##tmpTable
END
CREATE TABLE dbo.##tmpTable (
SomeField1 int,
SomeField2 decimal(15,2)
)


But this doesn't seems to work (table is not dropped even if it exists). What am I doing wrong?

Thanks for help.

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-02-04 : 04:37:52
try
If Object_Id('tempdb.#temptablename') is Not Null
Drop table #temptablename
Go to Top of Page

Wodzu
Yak Posting Veteran

58 Posts

Posted - 2008-02-04 : 04:50:34
Thanks, it works :)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-02-11 : 00:48:57
quote:
Originally posted by sunil

try
If Object_Id('tempdb..#temptablename') is Not Null
Drop table #temptablename


missing 1 dot


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -