SQL Server GROUP BY query does not consider case-sensitivity of data

The collation on my production SQL Server database unfortunately does not show me case-sensitive values when I do a group by, which is kind of inconvenient when your code is doing string matching.

In order to see this kind of differences, you have to introduce COLLATE entry like this example, where Items is the table name and Category is the column name of the NVARCHAR field that I want to do the case-sensitive group on:

SELECT Category COLLATE SQL_Latin1_General_CP1_CS_AS, COUNT(Category) 
FROM Items 
GROUP BY Category COLLATE SQL_Latin1_General_CP1_CS_AS

Leave a Reply