How can I do a case-sensitive comparison on a SQL Server installed with a case-insensitive sort-order?

Neil Pike

November 1, 1999

1 Min Read
ITPro Today logo

A. You can do this by converting the values to binary.

Assuming that you want to check a 4 character field to see if it has 'teST' in it (and you don't want to return values of 'test', 'TEST' etc.)

select * from
where convert(varbinary(4), ) = convert (varbinary(4), 'teST')

To compare between tables

select * from ,
where =
and convert(varbinary(4), ) = convert (varbinary(4), )

The reason for having the two comparisons here is so that any indices will still be used. They won't be used just with a comparison that uses convert.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like