I have a table (pages
) that holds properties for web pages, including a column for the page content itself, an NVARCHAR(MAX)
column.
Within that column, I need to find and replace a bunch of text strings and replace them with other text strings; these correlations are in a second table (moving
), with an oldValue
and newValue
column.
So, for example, if I'm starting with the two tables like this:
pages table:
ID Content
1 Words words Ancient words
2 Blah blah OutWithTheOld blah
3 Etc etc Useless etc
moving table:
OldValue NewValue
Ancient Better
OutWithTheOld InWithTheNew
Useless Useful
...I need a way of making a Replace that leaves the pages table like this:
ID Content
1 Words words Better words
2 Blah blah InWithTheNew blah
3 Etc etc Useful etc
It is possible that a given record in the pages table will need multiple replacements, and there's no way of predicting whether a pages record will have none, one, or many necessary replacements, or which values from moving.oldvalue
will be found and need to be replaced.
I'm using SQL Server 2008, and I'm fairly new to it. Thanks so much in advance for any help you can give!