I'm trying to run a recursive alter table reading a couple of parameters from my sys table.
DECLARE @AlterCmd NVARCHAR(MAX)
SELECT top 1
@AlterCmd = 'ALTER TABLE [dbo].[table] ALTER COLUMN ' + COLUMN_NAME + ' NVARCHAR(' + CHARACTER_MAXIMUM_LENGTH + ')'
FROM
information_schema.columns
WHERE
table_name = 'table_name' and DATA_TYPE like '%char%'
print @AlterCmd
In this sample code I just want to validate if the command is coming right but it's not possible to run it due an error in the concatenate. According to the error message I get:
Msg 245, Level 16, State 1, Line 63
Conversion failed when converting the varchar value ')' to data type int.