I'm using SQL 2012.
My current dataset looks like this:
shft_id code_id start_time end_time
9090 100 1/28/2015 07:15 1/28/2015 08:00
9090 100 1/28/2015 08:00 1/28/2015 08:30
9090 120 1/28/2015 08:30 1/28/2015 11:30
9090 110 1/28/2015 11:30 1/28/2015 13:00
9090 100 1/28/2015 13:00 1/28/2015 16:00
9090 100 1/28/2015 16:00 1/28/2015 16:30
9091 120 1/28/2015 11:00 1/28/2015 13:00
9091 110 1/28/2015 13:00 1/28/2015 15:30
9091 110 1/28/2015 15:30 1/28/2015 18:00
9091 110 1/28/2015 18:00 1/28/2015 18:30
9091 120 1/28/2015 18:30 1/28/2015 19:30
I need to consolidate consecutive start/end times based on the shft_id and code_id to the following desired output:
shft_id code_id start_time end_time
9090 100 1/28/2015 07:15 1/28/2015 08:30
9090 120 1/28/2015 08:30 1/28/2015 11:30
9090 110 1/28/2015 11:30 1/28/2015 13:00
9090 100 1/28/2015 13:00 1/28/2015 16:30
9091 120 1/28/2015 11:00 1/28/2015 13:00
9091 110 1/28/2015 13:00 1/28/2015 18:30
9091 120 1/28/2015 18:30 1/28/2015 19:30
Would anyone know the SQL that could accomplish this?
My current dataset looks like this:
shft_id code_id start_time end_time
9090 100 1/28/2015 07:15 1/28/2015 08:00
9090 100 1/28/2015 08:00 1/28/2015 08:30
9090 120 1/28/2015 08:30 1/28/2015 11:30
9090 110 1/28/2015 11:30 1/28/2015 13:00
9090 100 1/28/2015 13:00 1/28/2015 16:00
9090 100 1/28/2015 16:00 1/28/2015 16:30
9091 120 1/28/2015 11:00 1/28/2015 13:00
9091 110 1/28/2015 13:00 1/28/2015 15:30
9091 110 1/28/2015 15:30 1/28/2015 18:00
9091 110 1/28/2015 18:00 1/28/2015 18:30
9091 120 1/28/2015 18:30 1/28/2015 19:30
I need to consolidate consecutive start/end times based on the shft_id and code_id to the following desired output:
shft_id code_id start_time end_time
9090 100 1/28/2015 07:15 1/28/2015 08:30
9090 120 1/28/2015 08:30 1/28/2015 11:30
9090 110 1/28/2015 11:30 1/28/2015 13:00
9090 100 1/28/2015 13:00 1/28/2015 16:30
9091 120 1/28/2015 11:00 1/28/2015 13:00
9091 110 1/28/2015 13:00 1/28/2015 18:30
9091 120 1/28/2015 18:30 1/28/2015 19:30
Would anyone know the SQL that could accomplish this?