Home >> FAQs/Tutorials >> SQL Server FAQ
SQL Server FAQ  Converting Numeric Data Types by Assignment Operations
By: FYIcenter.com
(Continued from previous topic...)
How To Convert Numeric Expression Data Types by Assignment Operations?
An assignment operation is used to assign an expression to a variable, a column, or a parameter.
If the data type of the expression does not match the data type of the receiving variable, column, or parameter,
SQL Server will perform an implicit data type conversion on the expression.
Note that implicit data type conversion during assignment operation can convert a higher rank data type
to a lower rank data type, which may resulting in losing data during the conversion.
The tutorial exercise shows you some good examples:
 INT converted to NUMERIC
DECLARE @i INT;
DECLARE @d NUMERIC(9,3);
SET @i = 123;
SET @d = @i;
SELECT @d;
GO
123.000
 INT converted to NUMERIC
DECLARE @i INT;
DECLARE @d NUMERIC(9,3);
SET @i = 123;
SET @d = @i;
SELECT @d;
GO
123.000
DECLARE @pi FLOAT(24);
DECLARE @dp NUMERIC(5,2);
SET @pi = 3.1415927E+00;
SET @dp = @pi;
SELECT @dp;
GO
3.14
(Continued on next topic...)
 What Is an Expression?
 What Are Arithmetic Operators?
 What Happens to an Arithmetic Operation with Two Different Data Types?
 How To Convert a Numeric Expression from One Data Type to Another?
 How To Convert Numeric Expression Data Types by Assignment Operations?
 How To Convert Numeric Expression Data Types using the CAST() Function?
 How To Convert Numeric Expression Data Types using the CONVERT() Function?
 How To Convert Character Strings into Numeric Values?
 What Happens When Converting Big Values to Integers?
 What Happens When Converting Big Values to NUMERIC Data Types?
 What Are the Mathematical Functions Supported by SQL Server 2005?
 How To Convert Numeric Values to Integers?
 How To Round a Numeric Value To a Specific Precision?
 How To Generate Random Numbers with the RAND() Function?
