0

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.

  • But I can't insert them into the new column ? Can you describe it litle bit more, Do you want to update 3th column i table If yes whic type of data hold that column, Or you want to select results ? – adopilot May 23 '18 at 6:48
1

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))
0
select
cast(cast(cast(date  as date) as varchar(30))+' '+time  as datetime)
from column1

Here is sample

http://sqlfiddle.com/#!18/d8009/2

  • but this will just view the result. how to insert the result into a new column? – user151938 May 23 '18 at 6:38
  • INSERT INTO my_table (field, list) SELECT field,list FROM what_ever; – Vérace May 23 '18 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.