Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Working with money datatypes [Table of Contents] Creating user-defined datatypes

Transact-SQL User's Guide

[-] Chapter 6 Using and Creating Datatypes
[-] Mixed-mode arithmetic and datatype hierarchy
[-] Determining precision and scale

Determining precision and scale

For the numeric and decimal types, each combination of precision and scale is a distinct Adaptive Server datatype. If you perform arithmetic on two numeric or decimal values, n1 with precision p1 and scale s1, and n2 with precision p2 and scale s2, Adaptive Server determines the precision and scale of the results as shown in Table 6-4:

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)


Working with money datatypes [Table of Contents] Creating user-defined datatypes