sql server - T-SQL String template variables replacement -


ok, have table template data this

table templateformula  formula -------------------- [val1]+[val2]+[val1] [val3]/[val6]+[val1] ... 

and table variables

table templatedata  variable              value -----------           -------------- var1                  valueone var2                  twovalue var3                  othervalue ... 

what optimal way of mapping value template?

my solution create cursor go on variables , replace value in template. example

declare cursor c select variable, value templatedata ... update templateformula set formula = replace(formula, '[' + @variable + ']', @value) formula '%\[' + @variable + '\]%' escape '\' 

but that's kinda slow (since there can lot of variables, in case 10k variables), there faster way?


Comments