Tuesday, March 15, 2016

Case Sensitive in SQL Server

In this article, I am going to explain how to deal with case sensitive string in SQL query, On a general thought like you want to validate your login credential with SQL table by using  stored procedure, but by default match string and column value is not case sensitive in SQL.

Let's take an example,  firstly create a table for login and insert some value in it


create table U_Login
(
userid varchar(50) not null,
pwd varchar(50) not null
)
insert into U_Login (userid,pwd ) values ('sharad', 'sharad001')
insert into U_Login (userid,pwd ) values ('SHARAD', 'SHARAD001')

When you write given below query for login
select *  from U_Login  where userid='sharad' and pwd = 'sharad001'

Output

you can see above output image which shows both upper and lower case credentials.
But, we have just passed lower case credentials , so if you want to deal with case sensitive  information just write query as
SELECT *
FROM U_Login
WHERE userid = 'sharad' COLLATE SQL_Latin1_General_CP1_CS_AS
                AND pwd = 'sharad001' COLLATE SQL_Latin1_General_CP1_CS_AS


Now output

No comments:

Post a Comment