Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Case Sensitive String Compare

Tags:

sql

sql-server

How do you compare strings so that the comparison is true only if the cases of each of the strings are equal as well. For example:

Select * from a_table where attribute = 'k' 

...will return a row with an attribute of 'K'. I do not want this behaviour.

like image 362
amccormack Avatar asked Oct 19 '10 13:10

amccormack


People also ask

Are string comparisons case-sensitive in SQL?

A string comparison is case sensitive when you don't want it to be, or vice versa.

How do you do case insensitive comparison in SQL?

Case insensitive SQL SELECT: Use upper or lower functions or this: select * from users where lower(first_name) = 'fred'; As you can see, the pattern is to make the field you're searching into uppercase or lowercase, and then make your search string also be uppercase or lowercase to match the SQL function you've used.

Is compare to case-sensitive?

compareTo(string2) is case-sensitive. Meaning that all Capital letters come before the lowercase letters.


1 Answers

Select * from a_table where attribute = 'k' COLLATE Latin1_General_CS_AS  

Did the trick.

like image 73
amccormack Avatar answered Sep 28 '22 09:09

amccormack