Link to home
Start Free TrialLog in
Avatar of johnson1
johnson1

asked on

sql replace - words from another table

Hello,

I want to find all words in @StringTable where matching words are in Word column in @TableReplacelist and replace it with value from ReplaceWord column.

DECLARE @TableReplacelist table(Word varchar(50), ReplaceWord varchar(50))
INSERT INTO @TableReplacelist(Word,ReplaceWord)values('One','Eins')
INSERT INTO @TableReplacelist(Word,ReplaceWord)values('Two','Zwei')
INSERT INTO @TableReplacelist(Word,ReplaceWord)values('Three','Drei')
INSERT INTO @TableReplacelist(Word,ReplaceWord)values('Four','Vier')

DECLARE @StringTable table(Id int, MyString varchar(max))
INSERT INTO @StringTable(Id,MyString)values(1,'Here is One and Three')
INSERT INTO @StringTable(Id,MyString)values(2,'Here is One and Four')

If I would select all from @StringTable it should be modify like this:
1  Here is Eins and Drei
2  Here is Eins and Vier

Can you please suggest the best approach for this?
SOLUTION
Avatar of Aaron Tomosky
Aaron Tomosky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnson1
johnson1

ASKER

thank you for your help