The Advanced SQL Engine has 6 Numeric data types:
SQL Data Type | Description |
---|---|
ByteInt | Represents a 8-bit (1-byte) signed integer. Range: -128 to 127 |
BigInt | Represents an 64-bit (8-byte) signed integer. Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Decimal | Represents a decimal number with maximum precision of 38 but it can range from 1 to 38. The scale can range from 0 to 38 but it must be less than or equal to the precision. |
Double | Represents a 64-bit double-precision number. Range: ±2.226 x 10-308 to ±1.797 x 10308 |
Integer | Represents a 32-bit (4-byte) signed integer. Range: -2,147,483,648 to 2,147,483,647. |
Number |
Represents a fixed or floating point decimal. For fixed decimals the maximum precision is 38 and the scale can range from 0 to 38. The scale must be less than or equal to the precision. For floating decimals the mantissa can contain up to 38 digits, and the exponent can range from -130 to 125. |
SmallInt | Represents a 16-bit (2-Byte) signed integer. Range: -32,768 to 32,767 |
The "SQL Data Type and Literals" manual describes each type in detail. This sections shows how the SQL Engine Numeric data types map to the .NET type system.
The Base Class Library (BCL) has 7 Numeric data types:
Notable differences between the SQL Engine data types and BCL types are:
The .NET Data Provider for Teradata has serveral Numeric Provider Specific Types and each one can convert the SQL Engine Numeric data types to BCL types.
SQL Type | BCL Type | Provider Specific Type |
---|---|---|
ByteInt | System.Int16 | |
BigInt | System.Int64 | |
Decimal | System.Decimal | TdDecimal |
Double | System.Double | |
Integer | System.Int32 | |
Number | System.Double | TdNumber |
SmallInt | System.Int16 |
In each of the of Numeric Provider Specific Types, the number is stored as a scaled integer. Since the precision of a number can be up to 38, it is stored in four 32 bit unsigned integers. (Refer to TdDecimal.GetBytes() for more information).
The TdDecimal data type also contains operations that enable an application to operate on a Large Decimal. This includes the following types of operations:
The following is an example of using TdDecimal.
C# |
Copy Code |
---|---|
public void TdDecimalExample(TdCommand command) { command.Parameters.Clear(); // cost and retail_price are defined as Decimal (38, 2) command.CommandText = @"select cost, retail_price from Price where upc = 'upc1234' "; TdDataReader reader = command.ExecuteReader(); reader.Read(); // Reading the Decimals into a TdDecimal type TdDecimal cost = reader.GetTdDecimal(0); TdDecimal retailPrice = (TdDecimal) reader.GetProviderSpecificValue(1); // Going to add 10 percent to cost and retail price cost = cost + (cost * 0.10M); retail_price = retail_price * 1.10M; command.CommandText = @"update Price set cost = ?, retail_price = ? where upc = 'upc1234' "; // Setting up Parameters command.Parameters.Add(null, TdType.Decimal, 0, ParameterDirection.Input, true, 38, 2, null, DataRowVersion.Default, cost); command.Parameters.Add(null, TdType.Decimal, 0, ParameterDirection.Input, true, 38, 2, null, DataRowVersion.Default, retail_price); command.ExecuteNonQuery(); } |
Culture Specific Format of Numeric String
Conversion To and From Base Class Library System Types
Connection String Attributes Related to Large Decimals