MSSQL case sensitive queries

MSSQL will not search in a case sensitive way by default. Below are two popular ways to solve it.

»WHERE username = 'username' COLLATE SQL_Latin1_General_CP1_CS_AS

// Where CS in the end stands for Case Sensitive. If you change it with CI, you'll get Case INsensitive.


»WHERE CAST(username AS varbinary(8)) = CAST('username' AS varbinary(8))

// This works because the binary version of e.g. 'a' isn't equal to 'A'.


Written by: Dag Jonny Nedrelid
©2007-2012 http://thronic.com


Feel free to leave a comment.
Name:
URL:
0