title: How to insert a record into a table - depending on the total requiredQty from another table?
body: <p>I have this row in the database table:</p>
  <pre><code>ID       requiredQty 
  1088         30
  </code></pre>
  <p>And another table:</p>
  <pre><code>ID      orderLineID   bookedInQty
  3000       1088           10
  
  3001       1088           10
  </code></pre>
  <p><strong>dbfiddle: <a href="https://dbfiddle.uk/?rdbms=sqlserver_2019&amp;fiddle=9ecd8c83fcda08453481ec6d0ce45947" rel="nofollow noreferrer">https://dbfiddle.uk/?rdbms=sqlserver_2019&amp;fiddle=9ecd8c83fcda08453481ec6d0ce45947</a></strong></p>
  <p><strong>Summary</strong></p>
  <p>Total booked in quantity is total of <code>20</code> and <code>10</code> remaining for that particular order-line.</p>
  <p><strong>Question</strong></p>
  <p>How can I create an <code>if</code> statement to insert a record into the 2nd table, not to exceed table 1 <code>requiredQty: 30</code>?</p>
  <p><strong>Example</strong></p>
  <p>If insert <code>bookedInQty: 11</code> this means it exceeds <code>30</code> because there is an extra <code>1</code>. If it exceeds, simply do nothing.</p>
  <p>If to insert <code>bookedInQty: 9</code> this does not exceeds <code>30</code> because the total now equals to <code>29</code>. Then insert this record.</p>
  <p><strong>Note</strong></p>
  <p>Without creating any extra tables, I am trying to do it using an <code>if</code> statement.</p>