Case Sensitive SQL Query Search

Nohim Ys

Well-known member
  • Have you ever noticed when you do a string comparison in SQL using '=' notation, case of the string is neglected ???
    For example, If TestTable has a TestColumn and it consist of values ‘CaseSearch, casesearch, CASESEARCH, CaSeSeArCh’, following statement will return you all the four records.

    SELECT Column1
    FROM Table1
    WHERE Column1 = 'casesearch'

    If you dont want to ignore case and return only the exact row with the specified value, the query should be modified as follows,

    SELECT Column1
    FROM Table1
    WHERE Column1 COLLATE Latin1_General_CS_AS = 'casesearch'

    The above change should be done since the default Collation of the SQL Server installation SQL_Latin1_General_CP1_CI_AS is not case sensitive.



    Picked this from here - Reference
     

    Mal Baba

    Well-known member
  • Apr 26, 2009
    106,270
    5,599
    113
    Blob Storage
    www.37innovate.com
    Ela Wedak Ban
    11.gif
    11.gif
    11.gif
     

    Nohim Ys

    Well-known member