Andrew Myhre Andrew Myhre - 1 month ago 16
SQL Question

How do I perform a case-sensitive search and replace in SQL 2000/2005?

In order to perform a case-sensitive search/replace on a table in a SQL Server 2000/2005 database, you must use the correct collation.

How do you determine whether the default collation for a database is case-sensitive, and if it isn't, how to perform a case-sensitive search/replace?

Answer
SELECT testColumn FROM testTable  
    WHERE testColumn COLLATE Latin1_General_CS_AS = 'example' 

SELECT testColumn FROM testTable
    WHERE testColumn COLLATE Latin1_General_CS_AS = 'EXAMPLE' 

SELECT testColumn FROM testTable 
    WHERE testColumn COLLATE Latin1_General_CS_AS = 'eXaMpLe'

Don't assume the default collation will be case sensitive, just specify a case sensitive one every time (using the correct one for your language of course)

Comments