What Happens When Converting Big Values to Integers?
Submitted by: AdministratorIf you are converting a numeric expression to an integer data type and the value is too big for integer storage size, you will get an arithmetic overflow error as shown in the following examples:
-- Overflow error on implicit conversion
DECLARE @x FLOAT(24);
DECLARE @y TINYINT;
SET @x = 12345.12E+00;
SET @y = @x;
GO
Msg 232, Level 16, State 1, Line 4
Arithmetic overflow error for type tinyint,
value = 12345.120117.
-- Overflow error on explicit conversions
DECLARE @x FLOAT(24);
SET @x = 12345.12E+00;
SELECT CAST(@x AS TINYINT);
SELECT CONVERT(TINYINT, @x);
GO
Msg 232, Level 16, State 1, Line 4
Arithmetic overflow error for type tinyint,
value = 12345.120117.
Msg 232, Level 16, State 1, Line 5
Arithmetic overflow error for type tinyint,
value = 12345.120117.
Submitted by: Administrator
-- Overflow error on implicit conversion
DECLARE @x FLOAT(24);
DECLARE @y TINYINT;
SET @x = 12345.12E+00;
SET @y = @x;
GO
Msg 232, Level 16, State 1, Line 4
Arithmetic overflow error for type tinyint,
value = 12345.120117.
-- Overflow error on explicit conversions
DECLARE @x FLOAT(24);
SET @x = 12345.12E+00;
SELECT CAST(@x AS TINYINT);
SELECT CONVERT(TINYINT, @x);
GO
Msg 232, Level 16, State 1, Line 4
Arithmetic overflow error for type tinyint,
value = 12345.120117.
Msg 232, Level 16, State 1, Line 5
Arithmetic overflow error for type tinyint,
value = 12345.120117.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Use Subqueries with the IN Operators in MS SQL Server? |
☺ | How To Create a Testing Table with Test Data in MS SQL Server? |
☺ | How To Configure and Test ODBC DSN Settings? |
☺ | How To Create a Large Table with Random Data for Index Testing in MS SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |