title: Consolidate overlapping time periods stored as start and end time
body: <p>I have DB table with two columns of interest, the first is the start(or On) time, the second the end (or Off) time for numerous events within a given physical area.</p>
  
  <p>The requirement is to identify the unique period of time during which a vehicle was within the area. So the start of the first event to the end of the last as a continuous period. The number of on or off event in the period is not needed for the resulting table.</p>
  
  <p>There are millions of rows so a join may cause problems due to the size fo the resulting table. I'm not against it but...</p>
  
  <p>Data :</p>
  
  <pre><code>id          timeOn                    timeOff
  761058840   2018-01-02 07:54:28.000   2018-01-02 08:33:34.000
  761058840   2018-01-02 07:54:28.000   2018-01-02 08:36:30.000
  761058840   2018-01-02 08:33:45.000   2018-01-02 08:35:30.000
  761058840   2018-01-02 13:11:18.000   2018-01-02 13:14:04.000
  761058840   2018-01-02 13:11:18.000   2018-01-02 13:39:40.000
  761058840   2018-01-02 13:22:11.000   2018-01-02 13:40:25.000
  761058840   2018-01-02 15:56:18.000   2018-01-02 15:59:34.000
  761058840   2018-01-02 15:56:18.000   2018-01-02 16:36:25.000
  761058840   2018-01-02 16:01:34.000   2018-01-02 16:05:34.000
  761058840   2018-01-02 16:33:19.000   2018-01-02 16:38:26.000
  761058840   2018-01-02 21:20:25.000   2018-01-02 21:24:25.000
  761058840   2018-01-02 22:20:36.000   2018-01-03 05:20:37.000
  761058840   2018-01-02 22:20:36.000   2018-01-03 05:20:37.000
  761058840   2018-01-03 08:31:29.000   2018-01-03 09:01:10.000
  761058840   2018-01-03 08:31:59.000   2018-01-03 09:01:07.000
  761058840   2018-01-03 09:01:57.000   2018-01-03 09:06:27.000
  761058840   2018-01-03 14:07:27.000   2018-01-03 14:17:32.000
  761058840   2018-01-03 14:09:28.000   2018-01-03 14:45:00.000
  761058840   2018-01-03 14:19:32.000   2018-01-03 14:48:22.000
  761058840   2018-01-03 17:30:38.000   2018-01-03 18:06:35.000
  761058840   2018-01-03 17:33:54.000   2018-01-03 18:09:48.000
  </code></pre>
  
  <p>Consider the rows in this data, what I'm looking for is :</p>
  
  <pre><code>761058840   2018-01-02 07:54:28.000   2018-01-02 08:36:30.000
  761058840   2018-01-02 13:11:18.000   2018-01-02 13:40:25.000
  761058840   2018-01-02 15:56:18.000   2018-01-02 16:38:26.000
  761058840   2018-01-02 21:20:25.000   2018-01-02 21:24:25.000
  761058840   2018-01-02 22:20:36.000   2018-01-03 05:20:37.000
  761058840   2018-01-03 08:31:59.000   2018-01-03 09:01:07.000
  761058840   2018-01-03 09:01:57.000   2018-01-03 09:06:27.000
  761058840   2018-01-03 14:07:27.000   2018-01-03 14:48:22.000
  761058840   2018-01-03 17:30:38.000   2018-01-03 18:09:48.000
  </code></pre>
  
  <p>Other solutions are for dates, I have multiple events within an hour. other solutions are categorizing the events into periods (binning them by hours). </p>
  
  <p>There doesn't seem to be any things for continuous times.</p>
  
  <p>The DB is SQL Server so T-SQL or ANSI would be ideal but I'm prepared for a bit of translation.</p>
  
  <p>(edit for clarification : I'm trying to combine the sequence of overlapping times from timeOn to timeOff into a single row for each continuous sequence)</p>