I'm trying to build up a calculation string the values and operators will (eventually) be held in a SQL table. But for now i'm just testing it using the query analyzer. Please see example code below:
SET @MyCalcString = ''
SET @MyFirstNo = 10
SET @MySecondNo = 3
SET @MyStringPart = '/'
SET @MyCalcString = @MyCalcString + @MyFirstNo
SET @MyCalcString = @MyCalcString + @MyStringPart
SET @MyCalcString = @MyCalcString + @MySecondNo
create table #tmp1(result decimal(18,5))
select @MyResult = result from #tmp1
drop table #tmp1
So the calculation is : 10/3. Which results in an answer of 3.00000. Which is obviously wrong. If I declare the variables as 'decimal' then I can't build the calcation string, with an error of 'Error converting varchar to numeric'.