2

how to search case sensitive data like user_name and password in ms SQL server. In MySQl It is done by BINARY() function.

3

2 Answers 2

1

Can do this using Casting to Binary

SELECT * FROM UsersTable
WHERE   
    CAST(Username as varbinary(50)) = CAST(@Username as varbinary(50))
    AND CAST(Password as varbinary(50)) = CAST(@Password as varbinary(50))
    AND Username = @Username 
    AND Password = @Password
Sign up to request clarification or add additional context in comments.

4 Comments

Good answer, but use CAST reduces performance and, in some cases, the server will not be able to use indexes on these columns.
@Devart: Yes, Your answer is actual solution of this question. but i just posted this answer as another approach/solution.
I didn't want to criticize your answer :). I just wanted to inform you about possible problems when used this method.
Thank u so much Pankaj and Devart for your quick and accurate solution.It solved my problem.
0

Create column with case sensitive collate, and try this:

Query:

DECLARE @temp TABLE
(
      Name VARCHAR(50) COLLATE Latin1_General_CS_AS
)

INSERT INTO @temp (Name)
VALUES 
    ('Ankit Kumar'),
    ('DevArt'),
    ('Devart')

SELECT * 
FROM @temp
WHERE Name LIKE '%Art'

Output:

DevArt

Or try this similar code -

DECLARE @temp TABLE (Name NVARCHAR(50))

INSERT INTO @temp (Name)
VALUES 
    ('Ankit Kumar'),
    ('DevArt'),
    ('Devart')

SELECT * 
FROM @temp
WHERE Name LIKE '%Art' COLLATE Latin1_General_CS_AS

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.