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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop table syntax

Status
Not open for further replies.

gottaski

Programmer
Joined
Jan 4, 2001
Messages
17
Location
US
Can someone please help me w/ this syntax as I'm stumped:

DECLARE @mytable varchar(1000)

DECLARE @sqlCheck nvarchar(1000)

SET @mytable = 'tmp' + CAST(@@spid AS varchar(3))

SET @sqlCheck = 'if exists (select * from sysobjects where id = object_id(N'+ @mytable +') and OBJECTPROPERTY(id, IsUserTable) = 1) DROP TABLE '+@mytable+'
EXEC (@sqlCheck)

Any help would be greatly appreciated

Thanks.
 
You need a few more quotes:

SET @sqlCheck = 'if exists (select * from sysobjects where id = object_id(N'''+ @mytable +''') and OBJECTPROPERTY(id, IsUserTable) = 1) DROP TABLE '''+@mytable+''''


Chris Dukes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top