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)
 delete a temporary table from within a procedure

Author  Topic 

pssheba
Yak Posting Veteran

95 Posts

Posted - 2009-10-14 : 08:47:54
Hi everyone,
I'd like to create a temporary table from within a sp. That action will
fail if a temporary table of the same name already exists so i check if
it exists first using the following code:

IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID(tempdb..#xxx))
DROP TABLE tempdb..#xxx

But i get an error message that says:
quote:

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "tempdb..#xxx" could not be bound.


Anyone knows what that error message means ? Anyone knows how else i can delete that table ?
Thanks

rocknpop
Posting Yak Master

201 Posts

Posted - 2009-10-14 : 08:51:16
Apply single quotes in:

OBJECT_ID('tempdb..#xxx')

--------------------
Rock n Roll with SQL
Go to Top of Page

smarty
Starting Member

13 Posts

Posted - 2009-10-14 : 08:58:28
If object_id('tempdb..#xxx') IS NOT NULL
DROP TABLE tempdb..#xxx

-----------------------------------
Free SQL server monitoring for DBA's
www.realsmartsoftware.co.uk
Go to Top of Page

pssheba
Yak Posting Veteran

95 Posts

Posted - 2009-10-15 : 02:47:35
Thanks a lot, the error message was removed using that syntax
Go to Top of Page
   

- Advertisement -