Collections:
Converting DATETIME and NUMERIC Values in SQL Server
Are DATETIME and NUMERIC Values Convertible in SQL Server Transact-SQL?
✍: FYIcenter.com
Are datetime and numeric value convertible? The answer is yes. Here are the main rules on DATATIME and NUMERIC value conversions:
The tutorial exercise below shows you some good examples:
-- Implicit conversion NUMERIC to DATETIME DECLARE @birth_date DATETIME; SET @birth_date = 36583.25; SELECT @birth_date; GO 2000-02-29 06:00:00.000 -- Explicit conversion NUMERIC to DATETIME DECLARE @birth_date DATETIME; SET @birth_date = CONVERT(DATETIME, 36583.75); SELECT @birth_date; GO 2000-02-29 18:00:00.000 -- Implicit conversion DATETIME to NUMERIC DECLARE @birth_date DATETIME; DECLARE @birth_days NUMERIC(9,2); SET @birth_date = '2000-02-29 06:00:00.000'; SET @birth_days = @birth_date; GO Msg 257, Level 16, State 3, Line 4 Implicit conversion from data type datetime to numeric is not allowed. Use the CONVERT function to run this query. -- Explicit conversion DATETIME to NUMERIC DECLARE @birth_date DATETIME; DECLARE @birth_days NUMERIC(9,2); SET @birth_date = '2000-02-29 18:00:00.000'; SET @birth_days = CONVERT(NUMERIC(9,2), @birth_date); SELECT @birth_days; GO 36583.75
⇒ Subtracting a DATETIME Value from Another DATETIME Value in SQL Server
⇐ Converting Integers into Date and Time Values in SQL Server
⇑ Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-22, 1749🔥, 0💬
Popular Posts:
How To Convert Binary Strings into Hexadecimal Character Strings in SQL Server? When a query returns...
What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS) in SQL Server? Process sqlservr.exe is the...
What Are the Underflow and Overflow Behaviors on FLOAT Literals in SQL Server Transact-SQL? If you e...
How To Query Tables and Loop through the Returning Rows in MySQL? The best way to query tables and l...
How To Use "IF ... ELSE IF ..." Statement Structures in SQL Server Transact-SQL? "IF ... ELSE IF ......