Posted - 08/21/2014 : 11:33:02
| Hi there
Just using set based SQL (not cursors or procs) is there a way to do the following.
I have a single string (which is a formula) tokenised with variables. I want to replace this string via variable / values pairs which corresponding to different components of the formula.
How can this be done via t-sql only. Essentially its looping through variable / value pairs and each time replacing the formula string, then the next iteration use the previously manipulated formula to de-tokenise it further until the whole formula has been replaced.
So simple example: formula is A+B
Variable Value Pair1: A = 8
Variable Value Pair2: B = 3
1st iteration: 8 + B
2nd iteration: 8 + 3
I tried using cross apply but that gives me multiple rows. Maybe for xml path - but i don't like using hacks.
Thanks in advance. Jon