How can I replace all key fields in a string with replacement values from a table in T-SQL?

后端 未结 3 1068
情话喂你
情话喂你 2021-01-14 06:40

I have a table like:

 TemplateBody
 ---------------------------------------------------------------------
 1.This is To inform #FirstName# about the issues r         


        
3条回答
  •  遥遥无期
    2021-01-14 07:02

    As long as the values for the Variables are unique ('#FirstName#' etc.) you can join each variable to the table containing TemplateBody:

    select replace(replace(t.TemplateBody,'#FirstName#',variable.theVariable),'#Location#',variable2.theVariable)
    from
    [TemplateBodyTable] t
    left join
    (
    select TemplateValues theVariable,Variables
    from [VariablesTable] v
    ) variable on variable.Variables='#FirstName#'
    left join
    (
    select TemplateValues theVariable,Variables
    from [VariablesTable] v
    ) variable2 on variable2.Variables='#Location#'
    

提交回复
热议问题