Sure, more details:
I have a Fee Setup table in order to know how to calculate Customer fees for a given transaction, based on ranges of transaction amounts, for example:
To Country From $ To $ Calculate Formula
Puerto Rico 1.00 100.00 @yUsaAmt * 0.05
Puerto Rico 100.01 1000.00 (@yUsaAmt * 0.05) + @ySpecialChrg
And so on for many countries and ranges and other possible variables.
During my loop, I am scanning a set of transactions and have to calculate the Fee for every transaction, based on the formula.
From my transaction record I will pre-define values for @yUsaAmt and @SpecialChrg, Example:
Trans #1 Amount $ Special Charge Fee Formula $
0001 50.00 0.00 2.50
0002 150.00 3.00 10.50 ( $7.5 + $3.00)
The way to calculate the fee is dynamic, but parameters may be 1 or 2 or 3 or more. I just pre-define a set of possible variables but i don't know how many of them will be used in the formula, so I can't create a specific string to be processed through sp_executesql. In Fox we used to do it with just Evaluate() function.
I hope to be clear, and thank you again.
Juan.
>It's not clear what is relation between caling sproc in a loop and evaluating a string. Can you provide more details?
>
>>
>>Exactly, I am calling sp_executesql and one of the input parameters has to be a string, but this string is a variable expression which needs to be evaluated for the stored procedure to work fine because the stored procedure is called inside a loop.
>>
>>@expr = '@var1 + @var2' in the first loop, and next loop it may be:
>>@expr = '@var1 + @var2 + @var3 + @var4'
>>
>>
>>In some way, @expr is made of different variables but I need to convert it into only one: the evaluated expression.
>>