Collections:
Overflow and Rounding on NUMERIC Values in SQL Server Transact-SQL
How Extra Digits Are Handled with NUMERIC Data Type Literals in SQL Server Transact-SQL?
✍: FYIcenter.com
Exact numeric data types defined with NUMERIC(p,s) has two limits defined by two parameters: p (precision) and s (scale):
The tutorial exercise below gives an example of arithmetic overflow errors and rounding operations.
-- Exact numeric value DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 1234567.12; SELECT @x; ---------------------------- 1234567.12 -- Overflow error: p-s limit passed DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 123456789.12; ---------------------------- Msg 8115, Level 16, State 8, Line 2 Arithmetic overflow error converting numeric to data type numeric. -- Rounding on extra decimal digits: s limit passed DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 1234567.12345; SELECT @x; ---------------------------- 1234567.12
⇒ Approximate Numeric Data Types in SQL Server Transact-SQL
⇐ Overflow Errors with INT Values in SQL Server Transact-SQL
2017-04-19, 3147🔥, 0💬
Popular Posts:
How to change the data type of an existing column with "ALTER TABLE" statements in SQL Server? Somet...
How To Update Multiple Rows with One UPDATE Statement in SQL Server? If the WHERE clause in an UPDAT...
How To Select All Columns of All Rows from a Table with a SELECT statement in SQL Server? The simple...
Where to find answers to frequently asked questions on PHP Connections and Query Execution for MySQL...
How to execute statements under given conditions in SQL Server Transact-SQL? How to use IF ... ELSE ...