Hrides Thakur

Hrides Thakur

  • NA
  • 292
  • 49.7k

Find and replace multiple text string in sql server

Mar 16 2018 12:48 AM
Hi All
 
I have one table name EmailTemplate in that table i have a column EmailContent where i have data like below:
 
<div style='font-family: Verdana; font - size:10pt'>
Dear users,
<br/><br/>
__REQUEST_TYPE__ number: __NUMBER__ <br/>
Customer: __OEM_GROUP__ <br/>
Region/Division: __WORKFLOW_DIVISION__ <br/>
Program: __PROGRAM__ <br/>
Product line: __PRODUCT_LINE__ <br/>
<br/>
has been approved.<br/>
<br/>
This __REQUEST_TYPE__ was submitted with the following ratios:<br/>
 
With the following validation comments:
 
<ul> __COMMENT_LIST__ </ul>
</div>
 
when i select the this data, i want to replace all these bold contents e.g __REQUEST_TYPE__ with some values which i will get from another table in my select statements.
 
i want to avoid this kind of exercise below:
 
select replace(replace(replace(TemplateContent,'__REQUEST_TYPE__','Weekly'),'__NUMBER__','Twice Weekly'),'__OEM_GROUP__','china') as content from mytable;
please let me know suitable solution.
 
thanks.

Answers (3)