My issue is pretty similar to this question: Find start and end dates when one field changes
However, I've been unable to adapt the code to my situation. Any help would be greatly appreciated.
I have data which contains an ID, a variable called Type, and two datetime fields (one named Start and the other named Stop). This can be found here: http://sqlfiddle.com/#!6/35f43
Values for columns Start and Stop can run consecutively, and I want to combine those records grouping by ID and Type. The issue I currently have is I need to keep ID and Type separate if the Start and Stop datetimes are not consecutive.
For example, in the data on the SQLFiddle link, ID '3' currently has five records with type A with one record of type B in between.
ID Start Stop Type 3 2010-03-12 05:10:02.0000000 2010-03-20 12:00:00.0000000 A 3 2010-03-20 12:00:00.0000000 2010-04-07 09:46:30.0000000 A 3 2010-04-07 09:46:30.0000000 2010-05-01 08:13:42.0000000 B 3 2010-05-01 08:13:42.0000000 2010-07-04 09:30:32.0000000 A 3 2010-07-04 09:30:32.0000000 2010-07-06 11:41:38.0000000 A 3 2010-07-06 11:41:38.0000000 2010-07-09 12:51:30.0000000 A
I need this to show as:
ID Start Stop Type 3 2010-03-12 05:10:02.0000000 2010-04-07 09:46:30.0000000 A 3 2010-04-07 09:46:30.0000000 2010-05-01 08:13:42.0000000 B 3 2010-05-01 08:13:42.0000000 2010-07-09 12:51:30.0000000 A
Any ideas?