I declared a variable @avgMis as a decimal(2,2) in SQL Server. Then I tried to divide two integers, expecting a decimal value. Instead my answer is 0.00.
How do I divide @avgMis = (1/(1+2+1)) to get 0.25 in SQL Server?
I declared a variable @avgMis as a decimal(2,2) in SQL Server. Then I tried to divide two integers, expecting a decimal value. Instead my answer is 0.00.
How do I divide @avgMis = (1/(1+2+1)) to get 0.25 in SQL Server?
cast as decimal
DECLARE @x INT = 10, @y INT = 3, @z decimal(6,2)
SELECT @z = CAST(@x AS decimal(8,4))/CAST(@y AS DECIMAL(8,4))
SELECT @z
result would be 3.33
in your situation
SELECT CAST( CAST(1 AS DECIMAL(6,2))/CAST((1+2+1) AS DECIMAL(6,2)) AS DECIMAL(6,2)) AS result