Expert 2GB |
Two ways:
1. Use sp_executesql and use it's ability to return a parameter.
2. Take the long way: - declare @strFormula varchar(150), @intLength int, @inWidth int, @intHeight int, @intResult int
-
-
set @strFormula =
-
'
-
declare @FormulaResult int
-
set @FormulaResult = [Length] * [Width] * [Height]
-
select @FormulaResult as FormulaResult
-
'
-
-
select @intLength = 2, @inWidth = 5, @intHeight = 3
-
-
set @strFormula = replace(replace(REPLACE(@strFormula,'[Length]',cast(@intLength as varchar(3))),'[Width]', cast(@inWidth as varchar(3))),'[Height]',CAST(@intHeight as varchar(3)))
-
-
select @strFormula as strFormula
-
-
exec (@strFormula)
-
-
Good luck!
-- CK
| |