Thursday, February 18, 2010

SQL 2008 : Adding DATE and TIME back to DATETIME

SQL 2008 has DATE and TIME as separate data types at last.
But what if you need to fit them back together as a DATETIME?

SELECT CAST(CAST(mydate AS DATE) AS DATETIME) + CAST(mytime AS TIME)
FROM  [dbo].[mytable]

I'm sure there are other ways, I'd be interested to hear them, and any performance differences they provide!

Ref :
http://stackoverflow.com/questions/700619/combine-the-date-in-one-field-with-time-of-another-field-ms-sql-server

No comments: