Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to drop ##temp_tbl?

Status
Not open for further replies.

19511950

Programmer
Apr 4, 2003
46
US
How to drop global ##temp_tbl if exist, but if not don't drop.

When I try to run sp second time it says:
There is already an object named '##temp_tbl' in the database.

If I add into sp drop table '##temp_tbl' and try to run in a while it says:

Cannot drop the table '##temp_tbl', because it does not exist in the system catalog.

I need to have global ##temp_tbl not local #temp_tbl

Please help.
 
Hi

Try this,
-----
if exists(select * from tempdb..sysobjects where name = '##temp_tbl')
drop table ##temp_tbl
-----




---
Raj
 
Hi,

Try this TSQL

if not exists
(select * from [tempdb].[dbo].[sysobjects]
where id = object_id('[tempdb].[dbo].[##temp_tbl]'))
Drop table ##temp_tbl

Sunil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top