>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.
>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.
DECLARE @expr varchar(100), @sql nvarchar (200), @yUsaAmt money, @ySpecialChrg money, @yResult money; SET @expr = '(<<@yUsaAmt>> * 0.05) + <<@ySpecialChrg>>'; SET @yUsaAmt = 150.00; SET @ySpecialChrg = 3.00; SET @expr = REPLACE(@expr, '<<@yUsaAmt>>', CAST(@yUsaAmt AS varchar(20))); SET @expr = REPLACE(@expr, '<<@ySpecialChrg>>', CAST(@ySpecialChrg AS varchar(20))); SET @sql = N'SET @yResult = ' + @expr; EXECUTE sp_executesql @sql, N'@yResult money OUTPUT', @yResult OUTPUT; SELECT @yResult;