Case-sensitive SQL replace

Today i had to replace some words in an sql table, but it had to be done in a case-sensitive way, so that none of my capitalized words became lowercase.

I ended up with a small SQL script like this where Paragraph and ParagraphText are my table and me column:

1
2
3
UPDATE Paragraph  
SET ParagraphText = REPLACE(CAST(ParagraphText AS NVARCHAR(MAX)) COLLATE SQL_Latin1_General_CP1_CS_AS, 'ORIGINAL_WORD', 'NEW_WORD')
WHERE ParagraphText COLLATE SQL_Latin1_General_CP1_CS_AS LIKE '%ORIGINAL_WORD%'

This small script handles replaces like these:

bearbeitung -> verarbeitung
Bearbeitung -> Verarbeitung

If you have a better script or a more generic solution, feel free to add it in the comments below


Comments: