Exact Numeric Literals in SQL Server Transact-SQL

Q

What are exact numeric literals supported in SQL Server Transact-SQL?

✍: FYIcenter.com

A

Exact numeric literals in Transact-SQL are numbers written in standard signed decimal formats.

Exact numeric literals are used to provide values to exact numeric variables or table columns like INTEGER, DECIMAL(8,2), MONEY, etc.

Exact numeric literals are also used in exact numeric operations in expressions and exact numeric arguments in functions.

Here are some simple rules on how to write string literals:

  • An exact numeric literal should start with the sign mark, + or -, followed by the integer part, the decimal mark, and the fractional part.
  • For positive numbers, the positive sign mark is optional. For example, 9.0 and +9.0 are identical exact numeric literals.
  • For whole numbers, the decimal mark is optional. For example, 9 and 9. are identical exact numeric literals with a scale of 0.
  • Leading 0 in the integer part is optional. For example, 9.0 and 09.0 are identical exact numeric literals.
  • Trailing 0 in the fractional part represents an extra digit of scale. For example, 9.0 is an exact numeric literal with a scale of 1. 9.00 is an exact numeric literal with a scale of 2.

Here are some example on how to write exact numeric literals:

-- Identical exact numeric literals
PRINT 9;
PRINT 9.;

-- Identical exact numeric literals
PRINT 9.0;
PRINT +9.0;
PRINT 09.0;

-- Different exact numeric literals
PRINT 9;
PRINT 9.0;
PRINT 9.00;

-- Exact numeric literals in operation
PRINT 1.0/3;

 

Approximate Numeric Literals in SQL Server Transact-SQL

Unicode Character String Literals in SQL Server Transact-SQL

Data Literals in SQL Server Transact-SQL

⇑⇑ SQL Server Transact-SQL Tutorials

2017-05-05, 2475🔥, 0💬