title: SQL start time end time query
body: <p>so I have table like this</p>
  
  <pre><code>CREATE TABLE Table_Status
  (
  Status VARCHAR(10) NOT NULL,
  StartTime DATETIME NOT NULL, 
  EndTime DATETIME NOT NULL
  ); 
  </code></pre>
  
  <p>and data looks like this, <strong>StartTime and Endtime are consecutive time span</strong>:</p>
  
  <pre><code>Status1 2007-10-16 18:38:25.000 2007-10-17 05:30:22.000 
  Status2 2007-10-17 05:30:22.000 2007-10-17 18:48:46.000
  Status2 2007-10-17 18:48:46.000 2007-10-17 21:48:46.000
  Status1 2007-10-17 21:48:46.000 2007-10-18 08:11:59.000
  </code></pre>
  
  <p>So the idea is to <strong>SELECT * within any time period</strong>, if user pass two parameters </p>
  
  <pre><code>SET @From = '2007-10-17 00:00:00.000'
  SET @To = '2007-10-17 23:59:59.000' 
  </code></pre>
  
  <p>Somehow it should return table like this:</p>
  
  <pre><code>Status1 2007-10-17 00:00:00.000 2007-10-17 05:30:22.000
  Status2 2007-10-17 05:30:22.000 2007-10-17 21:48:46.000
  Status1 2007-10-17 21:48:46.000 2007-10-17 23:59:59.000
  </code></pre>
  
  <p>You see, the tricky part is to cut the original timespan to user defined timespan(@From - @To), I have been struggling with this whole day. Please advise.</p>
  
  <p>Thank you so much in advance!!!</p>