DISTINCT clause is case insensitive

Posted by Guru under Sql Server category on | Views : 3414
By default the DISTINCT clause is case insensitive, at least on a case inseneitive instance of SQL Server.
To Search For CASE Sensitive Distinct Values,use a COLLATE clause with a case sensitive collation. Here's a sample query with both case senstive and case insensitve collations. The data is all in the example, so give them a try.The COLLATE clause can make any string operation case sensitive.

select distinct (Item) COLLATE sql_latin1_general_cp1_cs_as
select 'abcd' item
union all select 'ABCD'
union all select 'defg'
union all select 'deFg') items

Comments or Responses

Login to post response