I’ve got a simple calculation (910 / 28 = 3.5) and I’m trying to perform this in a SQL query:
SELECT CONVERT(DECIMAL(5,2), (910 / 28),2) AS average
But the answer is coming out at 32.00, I’m obviously missing something simple could someone spare a moment to point out my error please?
Thanks, C
Advertisement
Answer
Use this:
SELECT CONVERT(DECIMAL(5,2), (910.0 / 28)) AS average
By taking the quotient as 910.0 / 28
SQL Server will retain decimal precision. Then, make your cast to a decimal with two places. By the way, as far as I know CONVERT
typically takes just two parameters when converting a number to decimal.