Sql-server – Combine date and time into one new column

sql serversql-server-2008

I have two columns named date and time respectively. Both of them have datatype nvarchar as they were imported from ms excel. I want to combine the column into a new column named datetime. I managed to get the result as I wanted by using:

SELECT date + ' ' + time as datetime
FROM column1

But I can't insert them into the new column.

Best Answer

Does the new column already exist? If it doesn't then you need to create it:

ALTER TABLE YourTable ADD [DateTime] DateTime2(0) NULL;

Then you go and "insert":

UPDATE YourTable
SET [DateTime] = CONVERT(DateTime2(0), (date + ' ' + time))