I have a date field [load_date
] and a datetime2 field [load_time
] that I want to combine into a datetime2. I want to combine load_date
with the time portion of load_time
and create a datetime2.
It's in an existing table, and I want to SET
the load_time
to this new value. Below is a SELECT
that appears to work, so I can turn this into an UPDATE
statement. However, I wanted to know if there is a more elegant or less verbose way.
SELECT
[load_date]
, [load_time]
, DATEADD(DAY, DATEDIFF(DAY, CAST(CAST([load_time] AS TIME) AS DATETIME2), CAST([load_date] AS DATETIME2)), CAST(CAST([load_time] AS TIME) AS DATETIME2))