Collections:
Converting Numeric Expressions from One Data Type to Another in SQL Server
How To Convert a Numeric Expression from One Data Type to Another in SQL Server Transact-SQL?
✍: FYIcenter.com
There are 4 ways to convert a numeric expression from one data type to another data type:
Some numeric data type conversion examples are provided in the tutorial exercise below:
-- Implicit conversion by an arithmetic operation -- INT converted to NUMERIC DECLARE @d NUMERIC(9,6); SET @d = 1.0; SELECT @d/3; GO 0.33333333 -- Implicit conversion by an assignment operation -- NUMERIC converted to INT DECLARE @i INT; DECLARE @d NUMERIC(9,3); SET @d = 123.456; SET @i = @d; SELECT @i; GO 123 -- Explicit conversion by CAST() -- FLOAT converted to NUMERIC DECLARE @pi FLOAT(24); SET @pi = 3.1415927E+00; SELECT CAST(@pi AS NUMERIC(5,2)); GO 3.14 -- Explicit conversion by CONVERT() -- FLOAT converted to NUMERIC DECLARE @pi FLOAT(24); SET @pi = 3.1415927E+00; SELECT CONVERT(NUMERIC(5,2), @pi); GO 3.14
⇒ Converting Numeric Data Types by Assignment Operations in SQL Server
⇐ Arithmetic Operations with Different Data Types in SQL Server
⇑ Numeric Expressions and Functions in SQL Server Transact-SQL
2017-03-27, 1478🔥, 0💬
Popular Posts:
How To List All User Names in a Database in SQL Server? If you want to see a list of all user names ...
What Happens to Your Transactions When ERROR 1213 Occurred in MySQL? If your transaction receives th...
How To Convert a Unicode Strings to Non-Unicode Strings in SQL Server Transact-SQL? Since Unicode ch...
How to set database to be READ_ONLY in SQL Server? Databases in SQL Server have two update options: ...
How To Verify a User name with SQLCMD Tool in SQL Server? The quickest way to verify a user name in ...