Veebster Veebster - 1 month ago 7
SQL Question

Combine split start and end time into one start and end time SQL Server

I need help with below, I'm trying to combine like date into one row

My current query provides the following,

ID Name Dept Hours Date Start_time End_time
--- ---- ---- ----- ---- ----------- ----------
1 John 01-A 4:45 10-18-2016 10-18-2016 06:00:00 10-18-2016 10:45:00
1 John 01-A 3:15 10-18-2016 10-18-2016 11:15:00 10-18-2016 14:30:00


I need a select statement to show this result

ID Name Dept Hours Date Start_time End_time
--- ---- ---- ----- ---- ----------- ----------
1 John 01-A 8:50 10-18-2016 10-18-2016 06:00:00 10-18-2016 14:30:00

Answer

Well assuming this is what you mean by Like data .

Select ID, Name, DEPT, SUM(HOURS), DATE, MIN(START_TIME),MAX(END_TIME)
from table
group by ID, Name, DEPT, DATE