MS SQL Server: Case Sensitive Search

Sometimes you need to search your database case-sensitive.
But: Microsoft SQL Server is usually configured to be case-INsensitive.

But there’s no need to reconfigure the whole database, here are my 2 favorites to lookup data:

  • cast column-value and searchterm to varbinary
    (e.g: CAST(ColName AS varbinary(4)) = CAST(‘andy’ AS varbinary(4))
  • use COLLATE
    (e.g: ColName = ‘andy’ COLLATE SQL_Latin1_General_CP1_CS_AS)

Both should work for SQL Server 2005 and above.
Interested in more options? Have look at this site!

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>