Case sensitive comparison in SQL Server

SQL Server compares strings without regard to case, which is a good thing most of the time, but can sometimes be annoying.

Luckily I found this article on case-sensitive string comparison, which gives a good overview of the possibilities:

  • cast the string to VARBINARY(length)
  • use COLLATE to specify a case-sensitive collation
  • calculate the BINARY_CHECKSUM() of the strings to compare
  • change the table column’s COLLATION property
  • use computed columns (implicit calculation of VARBINARY)

I chose the COLLATE SQL_Latin1_General_CP1_CS_AS method to perform the queries I needed.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.