Determining the datatype hierarchy  Datatype conversions

Chapter 1: System and User-Defined Datatypes

Determining precision and scale

For numeric and decimal datatypes, each combination of precision and scale is a distinct Adaptive Server datatype. If you perform arithmetic on two numeric or decimal values:

Adaptive Server determines the precision and scale of the results as shown in Table 1-3.

Table 1-3: Precision and scale after arithmetic operations

Operation

Precision

Scale

n1 + n2

max(s1, s2) + max(p1 -s1, p2 - s2) + 1

max(s1, s2)

n1 - n2

max(s1, s2) + max(p1 -s1, p2 - s2) + 1

max(s1, s2)

n1 * n2

s1 + s2 + (p1 - s1) + (p2 - s2) + 1

s1 + s2

n1 / n2

max(s1 + p2 + 1, 6) + p1 - s1 + p2

max(s1 + p2 -s2 + 1, 6)





Copyright © 2005. Sybase Inc. All rights reserved. Datatype conversions

View this book as PDF