Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to write sql query to retrieve user_id,user_name and password of the given user??


I have written the query

SQL
SELECT USER_ID,USER_NAME,PASSWORD FROM NC_USER WHERE USER_NAME = @USERNAME;


here USERNAME will be give by the end user.

In my mysql database the user table is saved in lower case.
Example:
user_id user_name password
1 chinmoyp m
2 sumitd mi
3 radhamadhaba min
4 bhagirathip mind
5 rashmis mindf

when i enter 'CHinmOYp' it is showing result.
user_id user_name password
1 chinmoyp m

But actually it should say invalid user name(error).

How to write a query so that the if we enter 'ChinmOYp' it will show an error message that the user name is not present.

Please Suggest

Thanks
Posted

You can try this..

SQL
SELECT USER_ID,USER_NAME,PASSWORD FROM NC_USER WHERE USER_NAME LIKE BINARY @USERNAME;


this binary keyword compares binary values so u can solve your problem
 
Share this answer
 
Comments
bhagirathimfs 6-Apr-12 9:41am    
Thanks :)
You can do it by forcing the COLLATION to case sensitive:

SQL
SELECT USER_ID,USER_NAME,PASSWORD FROM NC_USER WHERE USER_NAME = @USERNAME COLLATE SQL_Latin1_General_CP1_CS_AS
 
Share this answer
 
Comments
bhagirathimfs 6-Apr-12 5:46am    
It is showing error
"unknown collation:'SQL_Latin1_General_CP1_CS_AS'"
bhagirathimfs 6-Apr-12 5:47am    
SELECT USER_ID,USER_NAME,PASSWORD FROM NC_USER WHERE USER_NAME = ''CHinmoYP' COLLATE SQL_Latin1_General_CP1_CS_AS
when i execute this query it is showing the above error.
OriginalGriff 6-Apr-12 5:56am    
It may not be in your local SQL installation.
Run this query:
SELECT * FROM fn_helpcollations()
It will list all the collations installed. Chose an appropriate one from the list: the Description field needs to include "case-sensitive"
bhagirathimfs 6-Apr-12 7:02am    
The select query is showing error.
ERROR:U have an errorin the sql syntax;check manual that corresponds to your MySql server for the right syntax to use () in line 1.

Actually i am using the MYSQL 5.2

Can u suggest another way to know the collations.
OriginalGriff 6-Apr-12 7:05am    
Ah! MySql.
Have a look here: http://dev.mysql.com/doc/refman/5.5/en/charset-charsets.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900