Home Forums SQL Server 7,2000 T-SQL Sorting issue when meet there is ASCII RE: Sorting issue when meet there is ASCII

  • OK, you seem to have changed your collation, so here's what to do in general:

    (1) Go on to Wikipedia and search for "code page xxxx" where xxxx is the three or four digits that follow "Cp" in the name of the collation you are using. You'll come to a page like this.

    (2) Find a character in the character set that comes after every character that is used in your part_code.

    (3) Replace "-" in your part_codes with that character. Do that with a REPLACE function similar to the inner REPLACE you used before, but with the new character instead of Z and without a space before it. Put the REPLACE on both sides of the ">=". You don't need the outer REPLACE that you tried in your previous example.

    (4) You should end up with something like this:

    Select part_code

    from A_Test

    WHERE REPLACE(part_code,'-','~') COLLATE SQL_Latin1_General_Cp437_BIN >= REPLACE('RKS0516','-','~') COLLATE SQL_Latin1_General_Cp437_BIN

    ORDER BY part_code collate SQL_Latin1_General_Cp437_BIN

    John