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

Using the alter statement combined with parameters

Status
Not open for further replies.

Gruuka

Programmer
Aug 27, 2006
24
NL
Hey people I am trying to alter a table structure by using paramaters for the column name and type that alters expects.

Alter Table dbo.Tarieven Add @column_name @type

But this gives an error when i compile the procedure (i think it's due to the cast type of the parameters).
Can anyone give some pointers be it sites or advice on how to do this?

Thanks
 
I think you can't use variables like that. You need to do it like:
Code:
DECLARE @column_name VARCHAR(10)
DECLARE @type VARCHAR(15)
DECLARE @sql VARCHAR(200)

SET @sql = 'Alter Table dbo.Tarieven Add ' + @column_name + ' ' + @type

PRINT @sql
--EXEC (@sql)
Put the above code into a stored procedure. As the code is above, it won't 'do anything', it will only print out what the final command looks like. When you have it right, comment out the PRINT line and uncomment out the EXEC line.

-SQLBill


Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top