Replace method in SQL server

I was recently tasked to replace values in a SQL table’s columns that matched a certain criteria. In my case, I needed to basically switch words from “Discrete Digital%’ to ‘Digital Input%’.

Below is the syntax to use Replace  method.

1
2
3
UPDATE <table>
SET <column1> = REPLACE(string_expression, string_pattern, string_replacement)
WHERE <column1> LIKE <filter>;

in my case I used the following:

1
2
3
4
UPDATE MyDatabase
SET Column1 = REPLACE(Column1, ‘Discrete Digital’, ‘Digital Input’),
    Column2 = REPLACE(Column2, ‘Discrete Digital’, ‘Digital Input’)
WHERE Column2 LIKE ‘Discrete Digital%’;

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s