title: Delete Rows in SQL Table Based on Difference Between Values in Another Table
body: <p>I have one table (let's call it <code>dbo.temp</code>) that has minute by minute record of temperature from different sensors:</p>
  
  <pre>+-----------+------------+----------+------+
  | SENSOR_ID |   DATE     |   TIME   | TEMP |
  +-----------+------------+----------+------+
  |    106971 | 2017-01-10 | 10:05:00 | 21.1 |
  |    106971 | 2017-01-10 | 10:06:00 | 21.1 |
  |    106971 | 2017-01-10 | 10:07:00 | 21.2 |
  |    106971 | 2017-01-10 | 10:08:00 | 21.1 |
  |    106971 | 2017-01-10 | 10:09:00 | 21.1 |
  |    106971 | 2017-01-10 | 10:10:00 | 21.2 |
  |    106971 | 2017-01-10 | 10:11:00 | 21.2 |
  |    106971 | 2017-01-10 | 10:12:00 | 21.2 |
  |    106971 | 2017-01-10 | 10:13:00 | 21.3 |
  |    106971 | 2017-01-10 | 10:14:00 | 21.4 |
  |    106971 | 2017-01-10 | 10:15:00 | 21.4 |
  |    106971 | 2017-01-10 | 10:16:00 | 21.4 |
  |    106971 | 2017-01-10 | 10:17:00 | 21.5 |
  |    106971 | 2017-01-10 | 10:18:00 | 21.3 |
  |    106971 | 2017-01-10 | 10:19:00 | 21.3 |
  |    106971 | 2017-01-10 | 10:20:00 | 21.3 |
  |    106971 | 2017-01-10 | 10:21:00 | 21.4 |
  +-----------+------------+----------+------+</pre>
  
  <p>And a second (dbo.datetime) contains date and time values. </p>
  
  <pre>+-------------+-----------+----------+
  |    DATE     | TIME_A    | TIME_B  |
  +-------------+-----------+----------+
  | 2017-01-10  | 10:13:00  | 10:18:00 |
  | 2017-01-11  | 09:18:00  | 10:28:00 |
  | 2017-01-12  | 10:45:00  | 10:59:00 |
  +-------------+-----------+----------+
  </pre>
  
  <p>I want to delete rows in <code>dbo.temp</code> where the time is between the two given in <code>dbo.datetime</code> on any given date. <code>SENSOR_ID</code> is not important as all data between <code>TIME_A</code> and <code>TIME_B</code> needs to be deleted. </p>
  
  <p>For example I want dbo.temp to become this after the deletion between <code>TIME_A</code> and <code>TIME_B</code> on <code>2017-01-10</code>:</p>
  
  <pre>
  +-----------+------------+----------+------+
  | SENSOR_ID |   DATE     |   TIME   | TEMP |
  +-----------+------------+----------+------+
  |    106971 | 2017-01-10 | 10:05:00 | 21.1 |
  |    106971 | 2017-01-10 | 10:06:00 | 21.1 |
  |    106971 | 2017-01-10 | 10:07:00 | 21.2 |
  |    106971 | 2017-01-10 | 10:08:00 | 21.1 |
  |    106971 | 2017-01-10 | 10:09:00 | 21.1 |
  |    106971 | 2017-01-10 | 10:10:00 | 21.2 |
  |    106971 | 2017-01-10 | 10:11:00 | 21.2 |
  |    106971 | 2017-01-10 | 10:12:00 | 21.2 |
  |    106971 | 2017-01-10 | 10:19:00 | 21.3 |
  |    106971 | 2017-01-10 | 10:20:00 | 21.3 |
  |    106971 | 2017-01-10 | 10:21:00 | 21.4 |
  +-----------+------------+----------+------+</pre>
  
  <p>How do I do this? <code>dbo.datetime</code> has daily <code>TIME_A</code> and <code>TIME_B</code> values for ~14 months, so don't want to manually <code>delete from dbo.temp where date = 'X' and time between 'Y' and 'Z'</code> each day. </p>