locked
problem on convert Unicode (NVarchar) to Ascii (Varchar) RRS feed

  • Question

  • Is there any way to convert Unicode (NVarchar) to Ascii (Varchar)?

    If I just use cast , the result will become ???.

    Sunday, December 9, 2007 10:34 AM

Answers

  • IF the values in the unicode field are represented in the active codepage, you don't really have to convert to non-unicode.

     

    As you can see from this demonstration, there is no loss of data from a CAST() or CONVERSTION().

     

    DECLARE @MyVar nvarchar(20)
    SET @MyVar = He had a good Résumé'

     

    SELECT cast( @MyVar AS varchar(20) )

    --------------------
    He had a good Résumé

     

    HOWEVER, if the unicode value was 'high order' characters, they would NOT accurately CAST() or CONVERT() to non-unicode characters -AND there would be loss of data.

     

    SET @MyVar = 'ي شعاعي'
    SELECT cast( @MyVar AS varchar(20) )

     

    --------------------
    ? ?????

    Sunday, December 9, 2007 5:07 PM
  • Yes, Linda, that is correct.

    There is no way to convert or 'force' the display of Chinese charaters without programmatic support by the client application.

     

    Since, as you indicated, Crystal Reports v8 does not support unicode characters, you are hosed.

     

    Monday, December 10, 2007 12:41 AM

All replies

  • IF the values in the unicode field are represented in the active codepage, you don't really have to convert to non-unicode.

     

    As you can see from this demonstration, there is no loss of data from a CAST() or CONVERSTION().

     

    DECLARE @MyVar nvarchar(20)
    SET @MyVar = He had a good Résumé'

     

    SELECT cast( @MyVar AS varchar(20) )

    --------------------
    He had a good Résumé

     

    HOWEVER, if the unicode value was 'high order' characters, they would NOT accurately CAST() or CONVERT() to non-unicode characters -AND there would be loss of data.

     

    SET @MyVar = 'ي شعاعي'
    SELECT cast( @MyVar AS varchar(20) )

     

    --------------------
    ? ?????

    Sunday, December 9, 2007 5:07 PM
  • Actually, it the case that the values would be ??? since it contains chinese character. So, I really need to convert it to non-unicode since crystal report 8 dose not support unicode. If I use nvarchar as the data type, 

    do you mean there is no way to do it?  

    Sunday, December 9, 2007 8:52 PM
  • I don't think there is any way to translate one character to another like this.  To do this would be the equivalent of having to translate one chinese character (that represents an entire word in many cases, right?) to another completely different character.  This would seem to need to be a full translation tool, wouldn't it?

    Monday, December 10, 2007 12:06 AM
  • Yes, Linda, that is correct.

    There is no way to convert or 'force' the display of Chinese charaters without programmatic support by the client application.

     

    Since, as you indicated, Crystal Reports v8 does not support unicode characters, you are hosed.

     

    Monday, December 10, 2007 12:41 AM
  •  

    cast to XML and again cast to VARCHAR
    Monday, December 10, 2007 8:45 AM
  • Then, i need to throw away my crystal report and use excel export instead. Thanks of all!

    Monday, December 10, 2007 12:42 PM
  • Hi, linda,

    have you solve the proble of unicode charachters???

     

    Monday, April 28, 2008 10:39 AM