title: Copy a row once for each spanned hour
body: <p>I need to copy each row as many times as how many hours there are between <code>StartTime</code> and <code>EndTime</code>.</p>
  
  <p>Example data:</p>
  
  <p><strong><a href="http://sqlfiddle.com/#!3/587a4/1" rel="nofollow">SQLFIDDLEExample</a></strong></p>
  
  <pre><code>TimeKey HourKey SensorKey   IdleTimeMinute  StartTime   EndTime
  20121017    8   45  110 2012.10.17 08:31    2012.10.17 10:21
  20121017    10  45  25  2012.10.17 10:26    2012.10.17 10:51
  20121017    12  45  5   2012.10.17 12:21    2012.10.17 12:26
  20121017    12  45  60  2012.10.17 12:41    2012.10.17 13:41
  20121017    13  45  55  2012.10.17 13:51    2012.10.17 14:46
  20121017    15  45  5   2012.10.17 15:11    2012.10.17 15:16
  20121017    15  45  35  2012.10.17 15:46    2012.10.17 16:21
  20121017    18  45  5   2012.10.17 18:51    2012.10.17 18:56
  </code></pre>
  
  <p><strong>Explanation</strong></p>
  
  <p>For example, the first row spans the hours 8, 9, and 10. In each of the three output rows, <code>IdleTimeMinute</code> needs to be the minutes duration within that hour.</p>
  
  <p>Expected Result:</p>
  
  <pre><code>TimeKey HourKey SensorKey   IdleTimeMinute  StartTime   EndTime
  20121017    8   45  29  2012.10.17 08:31    2012.10.17 10:21
  20121017    9   45  60  2012.10.17 08:31    2012.10.17 10:21
  20121017    10  45  21  2012.10.17 08:31    2012.10.17 10:21
  20121017    10  45  25  2012.10.17 10:26    2012.10.17 10:51
  20121017    12  45  5   2012.10.17 12:21    2012.10.17 12:26
  20121017    12  45  19  2012.10.17 12:41    2012.10.17 13:41
  20121017    13  45  41  2012.10.17 12:41    2012.10.17 13:41
  20121017    13  45  9   2012.10.17 13:51    2012.10.17 14:46
  20121017    14  45  46  2012.10.17 13:51    2012.10.17 14:46
  20121017    15  45  5   2012.10.17 15:11    2012.10.17 15:16
  20121017    15  45  14  2012.10.17 15:46    2012.10.17 16:21
  20121017    16  45  21  2012.10.17 15:46    2012.10.17 16:21
  20121017    18  45  5   2012.10.17 18:51    2012.10.17 18:56
  </code></pre>
  
  <p><strong>Smaller Example</strong></p>
  
  <p>Smaller example from first two lines:</p>
  
  <pre><code>TimeKey HourKey SensorKey   IdleTimeMinute  StartTime   EndTime
  20121017    8   45  110 2012.10.17 08:31    2012.10.17 10:21
  20121017    10  45  25  2012.10.17 10:26    2012.10.17 10:51
  </code></pre>
  
  <p>For first line we have time <code>8:31 - 10:21</code> so In 8 Hour 29 Minutes, In 9 Hour 60 Minutes, In 10 Hour 21 Minute.</p>
  
  <p>Expected small result:</p>
  
  <pre><code>TimeKey HourKey SensorKey   IdleTimeMinute  StartTime   EndTime
  20121017    8   45  29  2012.10.17 08:31    2012.10.17 10:21
  20121017    9   45  60  2012.10.17 08:31    2012.10.17 10:21
  20121017    10  45  21  2012.10.17 08:31    2012.10.17 10:21
  20121017    10  45  25  2012.10.17 10:26    2012.10.17 10:51
  </code></pre>