SELECT DISTINCT --ROW_NUMBER() OVER (ORDER BY c.column_id) AS row_id c.name column_name , t.Name data_type , c.max_length , c.column_id --'ALTER TABLE ' + 'AD_AnaTablo' + ' ALTER COLUMN ' + c.name + ' ' + t.Name + '(' + CAST(IIf(t.name like 'nvar%',c.max_length/2,c.max_length) AS nvarchar(100)) + ') COLLATE ' + 'database_default' FROM sys.columns c JOIN sys.types t ON c.system_type_id = t.system_type_id LEFT OUTER JOIN sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id LEFT OUTER JOIN sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id WHERE c.object_id = OBJECT_ID('ResumeMaster') and t.Name like '%char%' ORDER BY c.column_id