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

Use of parameters in CREATE and DROP table commands

Status
Not open for further replies.

PBS2

Programmer
May 17, 2004
43
GB
I am trying to write a stored procedure in SQL2000 which will be called from an ASP.NET webpage. The procedure needs to create a table but as the name of the table varies I need to pass it as a parameter. The code I am trying to use is as follows:-

CREATE PROCEDURE XX_SamTest
@UserCode char(52), @SelectString char(1024)
AS

IF OBJECT_ID(@UserCode) IS NOT NULL

DROP TABLE @UserCode

CREATE TABLE @UserCode (
[CodeId] [uniqueidentifier]...............)

but the DROP and CREATE TABLE commands get rejected with a syntax error.

Can anyone advise on the correct syntax for this? Many thanks.
 
Does it work in QA? Is the vlaue that passed from the web is stored ina table or in a fly you are passing to sp. verify the use have dbo previllages.

Dr.Sql
Good Luck.
 
You'll need to use dynamic SQL to do this. Something like this.

Code:
declare @t1 varchar(255)
set @t1 = 'test'
exec ('drop table ' + @t1)

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
Donate to Katrina relief
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top