Tuesday, March 10, 2009

T-SQL Round Function Error : "An error occurred while executing batch. Error message is: Arithmetic Overflow."

PROBLEM:
I am doing sums of percentages have used the Round(99.999875,3) function to great avail to get a value of 100.000.

But, when I migrated to SQL 2K5, i used the same function and it gave me an arithmetic overflow error; more specifically:
"An error occurred while executing batch. Error message is: Arithmetic Overflow."

SELECT ROUND(99.999875,3)
-- An error occurred while executing batch. Error message is: Arithmetic Overflow

SOLUTION:

SELECT ROUND( CAST(99.999875 as decimal(10,3)), 3) -- 100.000

No comments: