# 15.00 - Binary Arithmetic Result Data Types - Teradata Database

## Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)

## Binary Arithmetic Result Data Types

The data type of the result of an arithmetic expression depends on the data types of the two operands. Operands are converted to the result type before the operation is performed.

For example, before an INTEGER value is added to a FLOAT value, the INTEGER value is converted to FLOAT, the data type of the result.

### Result Data Type

The following table shows the result data type for binary arithmetic operators.

The result data type for binary arithmetic operations involving UDT operands is the same as the result data type for the predefined data types to which the UDTs are implicitly cast.

For details on the result data type for binary arithmetic operations involving DateTime and Interval types, see “Arithmetic Operators and Result Types” on page 842.

### DECIMAL Result Data Type

The result data type for binary arithmetic operations involving DECIMAL operands is as follows:

 When the operand on the left is … And the operand on the right is … And the operator is … Then the result data type is … DATE DECIMAL(k,j) * / MOD DECIMAL(p,j) These operations on DATE do not report an error, but results are generally not meaningful. BYTEINTSMALLINTINTEGERBIGINT * / + - MOD DECIMAL(p,j) DECIMAL(m,n) BYTEINTSMALLINTINTEGERBIGINT + - * DECIMAL(p,n) DATE * DECIMAL(p,n) These operations on DATE do not report an error, but results are generally not meaningful.

In these cases the value of p, the number of digits in the decimal result, depends on:

• The value specified for MaxDecimal in DBSControl.
• For more information on DBSControl and MaxDecimal, see “DBS Control utility” in Utilities: Volume 1 (A-K).

• The number of digits in the decimal operand, where the number of digits is k for a DECIMAL(k,j) operand on the right side of the operator or m for a DECIMAL(m,n) operand on the left side of the operator.
•
 IF MaxDecimal is … AND the number of digits in the decimal operand is … THEN p is … 0 or 15 <= 15 15 > 15 and <=18 18 > 18 38 18 <= 18 18 > 18 38 38 any value 38

 When the operand on the left is … And the operand on the right is … And the operator is … Then the result data type is … DECIMAL(m,n) DECIMAL(k,j) + - DECIMAL(min(p,(1+max(n,j)+max(m-n,k-j))),max(n,j)) * DECIMAL(min(p,m+k),(n+j)) / MOD DECIMAL(p,max(n,j))

In these cases, the value of p in the definition of the decimal result data type depends on the value specified for MaxDecimal in DBSControl and the number of digits in the DECIMAL(m,n) and DECIMAL(k,j) operands.

 IF MaxDecimal is … AND … THEN p is … 0 or 15 m and k <= 15 15 (m or k > 15) and (m and k <=18) 18 m or k > 18 38 18 m and k <= 18 18 m or k > 18 38 38 m and k = any value 38

### Numeric Results and Rounding

When computing an expression, numeric results that are not exact are rounded, not truncated.

For more information on rounding rules and how the RoundHalfwayMagUp and RoundNumberAsDec fields in DBSControl affect rounding, see “Numeric Data Types” in SQL Data Types and Literals and “DBS Control utility” in Utilities: Volume 1 (A-K).

### Error Conditions

An error is reported when any of the following events occurs:

• Division by zero is attempted.
• The numeric range is exceeded.
• The exponentiation operator is used with a negative left argument and a right argument that is not a whole number.
• ### Integer Division and Truncation

Integer division yields whole results, truncated toward zero.