Collections:
Converting Numeric Data Types by Assignment Operations in SQL Server
How To Convert Numeric Expression Data Types by Assignment Operations in SQL Server Transact-SQL?
✍: FYIcenter.com
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
⇒ CAST() - Converting Numeric Expression Data Types in SQL Server
⇐ Converting Numeric Expressions from One Data Type to Another in SQL Server
⇑ Numeric Expressions and Functions in SQL Server Transact-SQL
2017-03-27, 1498🔥, 0💬
Popular Posts:
How To Look at the Current SQL*Plus System Settings in Oracle? If you want to see the current values...
How To Format Time Zone in +/-hh:mm Format in SQL Server Transact-SQL? From the previous tutorial, y...
How To Insert New Line Characters into Strings in SQL Server Transact-SQL? If you want to break a st...
How To Format DATETIME Values to Strings with the CONVERT() Function in SQL Server Transact-SQL? SQL...
How To List All Login Names on the Server in SQL Server? If you want to see a list of all login name...