(with a right thrown in for good measure) ... I want to take the date part of a date time field and combine it with a varchar field that has a time in the form of hh:mm PM or hh.mm AM and turn it into a single date time.Table Def and sample data:create table #Dates_Convert( serv_start_date datetime, serv_start_time varchar(8)) insert into #Dates_ConvertSELECT '2010-06-23 00:00:00.000', '11:30 AM' UNION ALLSELECT '2010-07-21 00:00:00.000', '03:00 PM' UNION ALLSELECT '2010-10-11 00:00:00.000', '01:00 PM' UNION ALLSELECT '2010-10-14 00:00:00.000', '03:15 PM' UNION ALLSELECT '2010-11-30 00:00:00.000', '04:00 PM' UNION ALLSELECT '2010-12-14 00:00:00.000', '03:45 PM' UNION ALLSELECT '2010-12-29 00:00:00.000', '10:30 AM' UNION ALLSELECT '2010-09-16 00:00:00.000', '08:45 AM' UNION ALLSELECT '2010-09-23 00:00:00.000', '09:30 AM' UNION ALLSELECT '2010-10-26 00:00:00.000', '02:05 PM'
So with a lot of trial and error; I came up with this:select serv_start_date ,serv_start_time-- ,cast(serv_start_date as varchar(10))-- ,convert(varchar(10),serv_start_date,120) -- ,convert(varchar(30),cast(serv_start_time as datetime),120)-- ,right(convert(varchar(19),cast(serv_start_time as datetime),120),9) ,cast(convert(varchar(10),serv_start_date,120) + right(convert(varchar(19),cast(serv_start_time as datetime),120),9) as datetime)from #dates_convert
Which works as it gives the result I want:serv_start_date serv_start_time results----------------------- --------------- -----------------------2010-06-23 00:00:00.000 11:30 AM 2010-06-23 11:30:00.0002010-07-21 00:00:00.000 03:00 PM 2010-07-21 15:00:00.0002010-10-11 00:00:00.000 01:00 PM 2010-10-11 13:00:00.0002010-10-14 00:00:00.000 03:15 PM 2010-10-14 15:15:00.0002010-11-30 00:00:00.000 04:00 PM 2010-11-30 16:00:00.0002010-12-14 00:00:00.000 03:45 PM 2010-12-14 15:45:00.0002010-12-29 00:00:00.000 10:30 AM 2010-12-29 10:30:00.0002010-09-16 00:00:00.000 08:45 AM 2010-09-16 08:45:00.0002010-09-23 00:00:00.000 09:30 AM 2010-09-23 09:30:00.0002010-10-26 00:00:00.000 02:05 PM 2010-10-26 14:05:00.000
But is there a better way?Laurie