Skip to content
Advertisement

SQL case sensitive compare

I like to know with a CASE statement wether two fields are the same.

I managed to do it with following query but I wonder if there is a better approach? I just want the ‘=’ to do a case sensitive compare. I tried with COLLATE but then I need to use a WHERE clause which filters my results, I want all the rows. And with HASHBYTES it seems overkill especially when I need to combine it with ISNULL

I need column ‘updated_isnull’

Advertisement

Answer

The proper solution would be to fix your columns so your data is stored in a case-sensitive collation. Then you would just do:

Using a case-insensitive collation, we could work around like this

Demo on DB Fiddle:

old  | new  | is_same
:--- | :--- | ------:
test | test |       1
test | TEST |       0
null | null |       1
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement