Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6

    Unanswered: unicode, is it just me or is this weird?

    Code:
    DECLARE @nstring nchar(12) = N'Åkergatan 24'
    
    --SELECT NCHAR(UNICODE(@nstring))
    CREATE TABLE #TEST
    (MyField VARCHAR(10)
    )
    
    DECLARE @One varchar(5) = '12345'
    
    DECLARE @Two nvarchar(5)= '6789' + NCHAR(UNICODE(@nstring))
    
    INSERT INTO #TEST
    SELECT @One + @Two
    
    SELECT * FROM #TEST
    
    DROP TABLE #TEST
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Not terribly weird. That character is code 197 on the default code page for SQL Server. The Unicode code for it is (you guessed it) 197. While it is a bad practice to mix and match UNICODE with VARCHAR when you deal with international character sets, you got away with it this time. Insert these lines in your sample. i would expect this will not work for Greek characters, Hebrew, Arabic, Cyrillic, or any of the Asian character sets.

    Code:
    SELECT ascii(substring (MyField, 10, 1)) FROM #TEST
    SELECT unicode(substring (MyField, 10, 1)) FROM #TEST

  3. #3
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    so you are good if the ascii code matches the unicode.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  4. #4
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Hold on. The ascii and unicode values do not match here but the value still got stored and retrieved. Everytime I think I know something...


    Code:
    DECLARE @nstring nchar(12) = N'œkergatan 24'
    
    --SELECT NCHAR(UNICODE(@nstring))
    CREATE TABLE #TEST
    (MyField VARCHAR(10)
    )
    
    DECLARE @One varchar(5) = '12345'
    
    DECLARE @Two nvarchar(5)= '6789' + NCHAR(UNICODE(@nstring))
    
    INSERT INTO #TEST
    SELECT @One + @Two
    
    SELECT * FROM #TEST
    SELECT ascii('œ') 
    SELECT unicode('œ') 
    
    DROP TABLE #TEST
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  5. #5
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Seems to be part of the implicit conversion from nchar to char. If you had a server with a non-default code page configured, you could test this a little further. Most of my tests with characters that were out of the scope of the local code page returned "?" for any "unknown" characters. This registered as character 63.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •