Hi,
I am trying to create a stored procedure to add a new column into a database from an ASP web application.
The SQL Code for this is:-
ALTER TABLE tablename
ADD COLUMN columnname columndatatype
I have tried to insert this SQL into a stored procedure:-
CREATE PROCEDURE sp_addcolumn
-- Add the parameters for the stored procedure here
@tablename varchar(50) = 0,
@columnname varchar(50) = 0,
@datatype varchar (50) = 0
AS
ALTER TABLE @tablename
ADD COLUMN @columnname @datatype
END
when i try to execture this i get an error message:-
"Msg 102, Level 15, State 1, Procedure sp_addcolumn, Line 7
Incorrect syntax near '@tablename'."
How I want this to work is - The user chooses which table they want to add a new column to from a drop down box which holds all the table names then they insert the column name and datatype.
I'm not sure what i have done wrong here, if anyone has any ideas they would be greatly appreciated! Thanks!
GLT