We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Convert all datatype nchar to nvarch on database

Medium Priority
292 Views
Last Modified: 2012-05-11
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
from information_schema.columns
where data_type = 'nchar'
order by 1,3
Comment
Watch Question

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.