Back
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?
A case sensitive search in WHERE clause can be done via changing the Collation. Because, by default, it is case insensitive.
Try this code:
SELECT 1FROM dbo.CustomersWHERE CustID = @CustID COLLATE SQL_Latin1_General_CP1_CS_AS AND CustPassword = @CustPassword COLLATE SQL_Latin1_General_CP1_CS_AS
SELECT 1
FROM dbo.Customers
WHERE CustID = @CustID COLLATE SQL_Latin1_General_CP1_CS_AS
AND CustPassword = @CustPassword COLLATE SQL_Latin1_General_CP1_CS_AS
Otherwise, change the columns to be case sensitive.
31k questions
32.8k answers
501 comments
693 users