Case sensitive comparison in SQL Server

SQL Server compares strings without regard to case.

If you need case sensitivity then consider one of the following options:

  • 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 normally change the COLLATE from Latin1_General_CS_AS to Latin1_General_CS_AS.

You can also consider the following method:
 Select * from T where convert(varbinary, code_id) = convert(varbinary, ‘Ab123C’)

What's your thoughts on this?


Protected by WP Anti Spam