Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Manipulating string via multiple rows

Author  Topic 

strauss_jon
Starting Member

23 Posts

Posted - 2014-08-21 : 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

   

- Advertisement -