SYMPTOMS
When adding two expressions e1 and e2 with scales s1 and s2 (each a decimal type) the expected result for the scale is the max(s1,s2) for the result.
For example:
e1 = 10.0001 s1 = 4
e2 = 10.000001 s2 = 6 -- max
e1+e2 = 20.000101 scale = 6
When either the
SUM or
AVG aggregates are used in one of the expressions, the scale of the result may be incorrect. In the case of
SUM, the resulting scale is the smallest scale provided as input to the
SUM function. In the case of the
AVG function, the scale is a fixed value that may not reflect either the scale of e1 or e2.