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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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