Select the product you need help with
PRB: Loss of Precision May Occur When You Use SUM or AVG Functions In a Formula with DivisionArticle ID: 281341 - View products that this article applies to. This article was previously published under Q281341 SYMPTOMS
When you use the SUM or AVG aggregate function with division, the result loses precision. The loss of precision occurs regardless of whether you use a numeric or decimal datatype.
CAUSE
This behavior is due to the nature of decimal and numeric datatypes and the truncation that occurs as a result of the precision and the scale values. According to SQL Server Books Online, the result of sum(numeric(p,s)) is numeric(38,s). In the preceding case, sum(amount) is numeric(38,9). When you have an expression of numeric(38,9) / numeric(15,9); ideally, the result is numeric(63,25). However, because the maximum precision is 38, the result truncates to (38,6).
WORKAROUND
To work around this behavior, use either of these methods:
MORE INFORMATION
To reproduce the behavior, run the following query from Query Analyzer:
However, if you use this code The loss of precision does not occur if you provide an explicit value in the denominator. Loss of precision does not occur if you put in the value of the sum: PropertiesArticle ID: 281341 - Last Review: October 16, 2003 - Revision: 3.2
|


Back to the top








