How to count continuous time frames
My data is as follows:
Id| Em_Name|Em_Reg_Date
--------------------------------
1 | John |2010-03-30 00:00:00
1 | John |2010-03-31 00:00:00
2 | Marc |2010-10-26 00:00:00
2 | Marc |2010-10-27 00:00:00
2 | Marc |2010-10-28 00:00:00
2 | Marc |2010-10-29 00:00:00
2 | Marc |2010-12-16 00:00:00
2 | Marc |2010-12-17 00:00:00
2 | Marc |2010-12-20 00:00:00
2 | Marc |2010-12-21 00:00:00
2 | Marc |2010-12-22 00:00:00
3 | Paul |2010-02-25 00:00:00
3 | Paul |2010-02-26 00:00:00
3 | Paul |2010-12-13 00:00:00
3 | Paul |2010-12-14 00:00:00
3 | Paul |2010-12-15 00:00:00
--------------------------------
A time interval is a continuous period of time. for example, Paul has the following two (2) time frames
FRAME 1 FROM 2010-02-25 00:00:00 to 2010-02-26 00:00:00
FRAME 2 FROM 2010-12-13 00:00:00 to 2010-12-15 00:00:00
So, the result should be like this:
1 John 1
2 Marc 3
3 Paul 2
Question: I need to calculate the time frame for each employee.
The problem here is that I need to isolate the ongoing time frames in order to count them. I even tried the ad cursor (it works, but I have to store the data in the temp table) And I want it to be in a βsimpleβ SQL statement Using max to find the start date only works for one frame. You cannot find the second / third frame with max.
Does anyone have any new fresh ideas?