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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to tell if a string conversion is safe?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

codism
Starting Member

11 Posts

Posted - 03/29/2007 :  12:49:51  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1837 Posts

Posted - 03/29/2007 :  13:09:21  Show Profile  Reply with Quote
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))

Edited by - snSQL on 03/29/2007 13:10:06
Go to Top of Page

codism
Starting Member

11 Posts

Posted - 03/29/2007 :  14:15:22  Show Profile  Reply with Quote
Nice idea! Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000