In an extract I am dealing with, I have 2 datetime
columns. One column stores the dates and another the times as shown.
How can I query the table to combine these two fields into 1 column of type datetime
?
Dates
2009-03-12 00:00:00.000
2009-03-26 00:00:00.000
2009-03-26 00:00:00.000
Times
1899-12-30 12:30:00.000
1899-12-30 10:00:00.000
1899-12-30 10:00:00.000
Prints:
Another way is to use
CONCAT
andCAST
, be aware, that you need to useDATETIME2(x)
to make it work. You can setx
to anything between0-7
7
meaning no precision loss.Returns
2018-03-12 07:00:00.0000000
Tested on SQL Server 14
This worked for me
(on SQL 2008 R2)
To combine date from a datetime column and time from another datetime column this is the best fastest solution for you:
Works like a charm
I had many errors as stated above so I did it like this
It worked for me.