Data being returned with upper ASCII chars changed!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • !NoItAll
    Contributor
    • May 2006
    • 297

    Data being returned with upper ASCII chars changed!

    I think I have the wrong collation set on a database I restored to a different server.
    Somehow the data in a varbinary field (it's used to store a date) is being returned incorrectly.
    Here's what I mean:
    In the query analyzer the data shows up as:

    0xDD3FC20120A42 A94000000000000 0000

    However with the following select statement:

    Code:
    select convert(char(8), itemdate) as mydate from item_data where itemid=12345678
    Instead of getting

    <DD><3F><C2><01 ><20><A4><2A><9 4>

    I get this mess

    <A6><3F><2D><01><20><F1><2A><F6>

    I think it has something to do with an incorrect collation setting because every character in the extended ASCII range (>7F) is returned translated. All of the characters in the lower ASCII range (01 to 7F) are returned properly.
    The current Collation name is: SQL_Latin1_Gene ral_CP850_CI_AS
    I think I need something that is designed for UTF8 - but I'm not sure...
    If I do need to change the collation - how do I do that? I can't find a setting to change it.
  • !NoItAll
    Contributor
    • May 2006
    • 297

    #2
    After further investigation I was right. Having the wrong collation was causing fields I was converting to char translated. Any char above 7F would get translated to the current collation set. When I restored the archive to my new machine it offered several collation options - clearly I chose the wrong one.
    To fix this it is very easy.

    I executed the following commands:

    select * from ::fn_helpcollat ions()

    This gave me a list of all the available collations. I chose a straight binary one - assuming no translation would take place with this in place.

    Latin1_General_ BIN

    So I then executed the following command (available from SQL 2000 and up)

    alter database [my_database] collate Latin1_General_ BIN

    Voila! I am now getting the chars untranslated and my calculations now produce the correct dates.

    I found the following article via Google:

    What is collation? Collation refers to a set of rules that determine how data is sorted and compared. Character data is sorted using rules that define the

    Comment

    Working...