Convert all datatype nchar to nvarch on database
Posted on 2011-04-20
I want to create a SQL statement that does the following
a) converts all nchar to nvarchar
b) trims off extra spaces from the fixed width: RTRIM(LTRIM(xxxxx_fieldname))
c) performs this action only on database tables, not views
I know the following select statement gets the schema, but I have no idea how to perform the actions above on each field--can someone help?
select TABLE_NAME, COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, ORDINAL_POSITION
where data_type = 'nchar'
order by 1,3