SQL statements can involve arithmetic expressions that use decimal data types of different precisions (the total number of digits, both to the left and to the right of the decimal point) and scales (the number of digits of the fractional component). The precision and scale of the resulting decimal type depend on the precision and scale of the operands.
Given an arithmetic expression that involves two decimal operands:
Use the following formulas to determine the scale of the resulting data type for the following kinds of arithmetical expressions:
ls + rs
31 - lp + ls - rs
max(max(ls, rs), 4)
max(ls, rs)
For example, the scale of the resulting data type of the following
expression is 27:
Use the following formulas to determine the precision of the resulting data type for the following kinds of arithmetical expressions:
lp + rp
2 * (p - s) + s
lp - ls + rp + max(ls + rp - rs + 1, 4)
max(lp - ls, rp - rs) + 1 + max(ls, rs)