title: SQL Server count between before and after midnight - 24 hours
body: <p>I need to count records between before midnight and after midnight with a field that uses 24 hour datetime. The following statement has worked perfectly for times that are in the same day, e.g. between 10:30 am and 4:29 pm:</p>
  
  <pre><code>WHERE CAST (theader_tdatetime AS time) BETWEEN '10:30' and '16:29' 
  </code></pre>
  
  <p>However, I need to also select records from 7:31 pm to 2:00 am, and my statement no longer works:</p>
  
  <pre><code>WHERE CAST (theader_tdatetime AS time) BETWEEN '19:31' and '02:00' 
  </code></pre>
  
  <p>How can I select records from this timeframe?</p>
  
  <p>Edit: A few sample records that bridge the midnight gap</p>
  
  <pre><code>2015-11-20 23:48:52.000  
  2015-11-20 23:49:58.000  
  2015-11-20 23:51:35.000  
  2015-11-20 23:58:51.000  
  2015-11-20 23:59:26.000  
  2015-11-21 00:04:03.000  
  2015-11-21 00:04:36.000  
  2015-11-21 00:05:11.000  
  </code></pre>