thanks but i need to preserve the field name.
Main Topics
Browse All TopicsI want to convert some ntext fields in a table to varchar, keeping the same column name and data. Is there a way to do this in sql?
Thanks, Tom.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
At the semantic level (not filling in all the syntax) it would look like this:
1. Alter table add temp_column as varchar(8000)
2. update mytable set temp_column=cast (left(8000,Old_column) as varchar) <- this safeguards against oversize data by truncating
3. alter table drop Old_column
4. alter table add Old_column as varchar (8000)
5 update mytable set old_column=temp_column
6. alter table drop temp_column.
That would work as long as the Ntext data doesn't violate the size restrictions of varchar.
Fast query to find it would be
Select max len(column) from mytable
this should return the longest data element in your column.
I did test this and it does work. It's very fast I might add. I ran it on a table we have with 24000 rows.
Hmmm...
If all else fails resort to the GUI.
If this is a one time task then you could use EM.
go in, add the new column using "design table" in EM.
Test your column length to see if you have a data issue.
If you don't have a data issue, copy the data to the new column.
Then go back to EM and drop the offending column using design table.
Delete, save. Add new column with same name. Save.
Copy data back.
go back to "design" and drop temp column.
Accomplishes the same thing with some extra mouse work and not having to figure out the intracies of alter table statements.
I freely admit I'm a wimp when it comes to alter table. I'm afraid I'll type the wrong thing and zap data. So I go through the gui. modify, check, and then save.
And on certain tables I do a Select Into to make a backup first.
I call it my "nights and weekends free plan".
Ok, my bad, I apologize. ntext columns cannot be altered.
From MSSQL manual:
...
ALTER COLUMN
Specifies that the given column is to be changed or altered. ALTER COLUMN is not allowed if the compatibility level is 65 or earlier. For more information, see sp_dbcmptlevel.
The altered column cannot be:
A column with a text, image, ntext, or timestamp data type.
...
Thanks mate. I would recommend begin transaction & rollback transaction.!
My nights and weekend free plan distrusts gui's!
still playing with it but step 2
2. update mytable set temp_column=cast (left(8000,Old_column) as varchar)
is giving
Operand type clash: ntext is incompatible with int
at the moment....
Business Accounts
Answer for Membership
by: ichthus1Posted on 2004-12-21 at 05:38:18ID: 12875514
select cast(ntext_field) as varchar(8000)) as newfieldname
where 8000 is the maximum size you may set in varchar.
remember, ntext is of unlimited size, and varchar is limited.
This will oly work if the size of the Ntext field is 8000 non-unicode bytes or smaller