sqlsql-server

"SELECT DISTINCT" ignores different cases


I have the problem, that MSSQL Server 2000 should select some distinct values from a table (the specific column is of the nvarchar type). There are the sometimes the same values, but with different cases, for example (pseudocode):

SELECT DISTINCT * FROM ("A", "a", "b", "B")

would return

A,b

But I do want (and do expect)

A,a,b,B

because they actually are different values.

How to solve this problem?


Solution

  • The collation will be set to case insensitive.

    You need to do something like this

    Select distinct col1 COLLATE sql_latin1_general_cp1_cs_as
    From dbo.myTable