|   | ![]() |
|
How can I do a case-sensitive
comparison on a SQL Server installed with a case-insensitive sort-order? 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 <tbl> where convert(varbinary(4), <col>) = convert (varbinary(4), 'teST') To compare between tables select * from <tbl1>, <tbl2> where <tbl1.col> = <tbl2.col> and convert(varbinary(4), <tbl1.col>) = convert (varbinary(4), <tbl2.col>) 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. |
All content on this site, except where noted, represents an original work of Michael R. Hotek and is protected by applicable copyright laws. The SQL Server FAQ is the sole work of Neil Pike. No page, portion of a page, or download may be used for commercial purposes in whole or in part without the express, written permission of the applicable author.