2 fields into 1

  • I have this table that has a date and time in 2 sepearte fields and I want to put them into 1 field with the datatype of datetime. I was wondering if there was a way with tsql to do it or will i be stuck writing a asp.net program to convert it which I know I can do. Any thoughts?

    Matt

  • Here is a method to do it. I'm sure your situation is slightly different but maybe something similar to this might work for you:

    create table test_t(

    datef char(10),

    timef char(8),

    datetimef datetime)

    insert into test_t (datef, timef) values ('01/01/1990','09:15 PM')

    insert into test_t (datef, timef) values ('07/21/2001','03:13 AM')

    insert into test_t (datef, timef) values ('06/03/1967','10:49 PM')

    update test_t

    set datetimef = cast(datef + ' ' + timef as datetime)

    select * from test_t

    dropt test_t

    -------------------------

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply