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 2000 Forums
 SQL Server Development (2000)
 Dropping a Table in a Stored Proc

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-12-06 : 10:01:54
Lou writes "How can i drop a table in a stored proc. when the table name is passed to the Stored Proc. as a Variable?

Drop Table @tablename does not work....

Any help would be appreciated.

Lou"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2001-12-06 : 11:05:58
Some dynamic SQL will do the trick:

http://www.sqlteam.com/item.asp?ItemID=4599
http://www.sqlteam.com/item.asp?ItemID=4619

Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2001-12-06 : 11:07:01
You have to do it dynamically.


exec('drop table ' + @tablename)

Go to Top of Page
   

- Advertisement -