Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to tell if a string conversion is safe?

Author  Topic 

codism
Starting Member

11 Posts

Posted - 2007-03-29 : 12:49:51
I need to alter a table to change a nvarchar column to varchar column. The problem is that the column already contained many data. Before altering the table, I want to know if such a conversion is safe or not for all existing data because varchar does not cover all unicode code points.

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-29 : 13:09:21
Run a query like this on the table and if it returns any rows then you are going to lose unicode data, or at least it will be different after converting to varchar. Assuming your nvarchar is 20 characters (change the query to match how long your nvarchar is)

SELECT yourcol AS [Unicode], cast(yourcol as varchar(20)) AS [NonUnicode]
FROM yourtable
WHERE yourcol <> cast(yourcol as varchar(20))
Go to Top of Page

codism
Starting Member

11 Posts

Posted - 2007-03-29 : 14:15:22
Nice idea! Thanks
Go to Top of Page
   

- Advertisement -