How to do a case sensitive search in WHERE clause (I'm using SQL Server)?

Viewed 327396

I want to do a case sensitive search in my SQL query. But by default, SQL Server does not consider the case of the strings.

Any idea on how to do a case sensitive search in SQL query?

11 Answers
select * from incidentsnew1 
where BINARY_CHECKSUM(CloseBy) = BINARY_CHECKSUM(Upper(CloseBy))

You can do by simply altering column collation as

Alter Table UserMaster 
Alter Column Password varchar(50) COLLATE SQL_Latin1_General_CP1_CS_AS

Just as others said, you can perform a case sensitive search. Or just change the collation format of a specified column as me. For the User/Password columns in my database I change them to collation through the following command:

ALTER TABLE `UserAuthentication` CHANGE `Password` `Password` VARCHAR(255) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL;
Related