Re: How do i perform a case sensitive search??

From: Anith Sen (anith_at_bizdatasolutions.com)
Date: 09/27/04


Date: Mon, 27 Sep 2004 11:17:40 -0500

You can use COLLATE clause with a case sensitive collation, cast the value
to a binary type or use a CHECK_SUM comparison ( in trivial cases ). For
example you can have your query like:

SELECT *
  FROM members
 WHERE user_ = 'abc'
   AND password_ COLLATE SQL_Latin1_General_CP1_CS
     = 'AbCd' ;

You can get a list of valid collation names for Windows & SQL using:

SELECT *
  FROM ::fn_helpcollations()

For smaller strings you can use another method where you convert the string
value to a binary type like :

SELECT *
  FROM members
 WHERE user = 'abc'
   AND CAST( password_ AS VARBINARY )
     = CAST( 'AbCd' AS VARBINARY )

Read through the topics related to COLLATE and CAST & CONVERT for
explanations & examples of using CAST/CONVERT functions as well as the exact
syntax details. Also, just wanted to add, using reserved words like
"password" for column names is not generally a good idea.

-- 
Anith 


Relevant Pages

  • Re: Is this a bug in SQL or by design??
    ... Looks like a bug. ... when you cast one of the parameters to unicode. ... SELECT REPLACE('ab' COLLATE Latin1_General_CI_AS, 'a', N'a ') ...
    (microsoft.public.sqlserver.programming)
  • Re: Cannot resolve collation conflict for equal to operation.
    ... can use a collate clause or you can cast one of the columns. ... > Declare @TempName table ...
    (microsoft.public.sqlserver.server)
  • Re: Flexible Collating (feedback please)
    ... Although it is still quite a bit slower than a bare list.sort, that is to be expected as collate is locale aware and does additional transformations on the data which you would need to do anyways. ... Changed the flag types from integer values to a list of named strings. ... The reason for this is it makes finding errors easier and you can examine the flags attribute and get a readable list of flags. ... It now separates numerals in the middle of the string. ...
    (comp.lang.python)
  • Collate Module
    ... I've made a few more changes to my little collate module. ... Collate.py - Sorts lists of strings in various ways depending ... To use collate with your user locale you need to call setlocale ... flags = flags.upper.split ...
    (comp.lang.python)