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

  • John Mitchell-245523 (7/25/2013)


    If removing the space before the Z doesn't do it, please post table DDL in the form of CREATE TABLE statements, sample data in the form of INSERT statements, and the results you expect to see given the sample data.

    John

    Hi John,

    Thanks again.

    I reproduce the scenario from same SQL 2008 R2 server and here below is as per your request,

    CREATE TABLE [dbo].[A_Test] (

    [part_code] varchar(50) COLLATE Chinese_PRC_Stroke_90_CI_AS NOT NULL

    )

    ON [PRIMARY]

    GO

    INSERT INTO [dbo].[A_Test] ([part_code])

    VALUES (N'RKS0516-W')

    GO

    INSERT INTO [dbo].[A_Test] ([part_code])

    VALUES (N'RKS0516-W-Z')

    GO

    INSERT INTO [dbo].[A_Test] ([part_code])

    VALUES (N'RKS0516A-W')

    GO

    INSERT INTO [dbo].[A_Test] ([part_code])

    VALUES (N'RKS0516A-W-Z')

    GO

    INSERT INTO [dbo].[A_Test] ([part_code])

    VALUES (N'RKS0530-A')

    GO

    INSERT INTO [dbo].[A_Test] ([part_code])

    VALUES (N'RKS0530-A-SP')

    GO

    1) Result from this query is correct,

    ----------------------------------

    Select part_code,

    from A_Test

    WHERE part_code>='RKS0516'

    ORDER BY part_code collate SQL_Latin1_General_Cp437_BIN

    RKS0516-W

    RKS0516-W-Z

    RKS0516A-W

    RKS0516A-W-Z

    RKS0530-A

    RKS0530-A-SP

    But, when I change the filter value from 'RKS0516' to 'RKS0516-W', the result shows missing of 2 records

    RKS0516-W

    RKS0516-W-Z

    RKS0530-A

    RKS0530-A-SP

    I am expecting the result should like the first query.

    Together, we can make wonders!