Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

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?

1 Answer

0 votes
by (40.7k points)

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 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.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 11, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 11, 2019 in SQL by Tech4ever (20.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...