Sunday, March 25, 2012

Case Sensitive VarChar comparsion???

Hi all,
I wonder if it is possible to use case sensitive varchar comparsion in a query?
As I have tried and the varchar comparsion is non-case sensitive.
Thanks
MEif (convert (varbinary,'Enigma')= convert (varbinary,'enigma'))
Print 'Done'
else
Print 'Not Done'

if (convert (varbinary,'Enigma')= convert (varbinary,'Enigma'))
Print 'Done'
else
Print 'Not Done'|||For a case-sensitive compare, I'd use:IF 'PatP' = 'patp' COLLATE SQL_Latin1_General_CP1250_CS_AS
PRINT 'Match'
ELSE
PRINT 'Different'You can get a list of collations that a given server will support using:SELECT *
FROM ::fn_helpcollations()-PatP|||Pat ... any reason you would not recommend a cast to varbinary|||Two reasons.

First of all, if you want a string compare, I think you should do a string compare... There are lots of ways to compare strings, and keeping that flexibility is important to me. Today the users want case sensitivity, tomorrow they'll want the strings ordered using the Spanish dictionary, which is easy using a collation.

Second, casting to BINARY has a cost, and in large jobs that cost can get high. Why incur overhead that gives no real benefit?

-PatP|||Thanks ...
Learned something new again ...

No comments:

Post a Comment