Reputation: 1024
Aim:
Alter multiple columns from a newly created table
I had the columns I wanted to modify in the code but have chopped it down to one for this example, there is nothing obvious I can see. I have an even number of brackets and so forth. Nothing is more than 200 characters long.
Code:
DECLARE @tableALTER NVARCHAR(2500)
SET @tableALTER = '
(ALTER TABLE ' + @tableName + ' ALTER COLUMN [ID] VARCHAR(200))'
EXEC (@tableALTER)
Using:
SQL Server Management Studio
Error:
Incorrect syntax near the keyword 'ALTER'.
Incorrect syntax near ')'.
Research includes:
How to change the data type of a column without dropping the column with query?
Upvotes: 2
Views: 3207
Reputation: 1746
How about removing the opening and closing parenthesis inside the string.. try this..
DECLARE @tableALTER NVARCHAR(2500)
SET @tableALTER = 'ALTER TABLE ' + @tableName + ' ALTER COLUMN [ID] VARCHAR(200)'
EXEC (@tableALTER)
Upvotes: 5