title: How to create a condition for this case?
body: <p>Sample Table:</p>
  
  <pre><code>Id |Acc_Code|Description       |Balance   | Acclevel| Acctype| Exttype|
  --- -------- ----------------- |--------  |-------- | -------| -------|
  1  |SA      |Sales             |   0.00   |   1     |  SA    |        |
  2  |CS      |Cost of Sales     |   0.00   |   1     |  CS    |        |
  3  |5000/001|Revenue           |  94.34   |   2     |  SA    |        |
  4  |5000/090|Sales(Local)      |  62.83   |   2     |  SA    |        |
  5  |7000/000|Manufacturing Acc |-250.80   |   2     |  CS    | MA     |
  6  |7000/200|Manufacturing Acc | 178.00   |   2     |  CS    |        |
  </code></pre>
  
  <p>This is a sample data of a temporary table which would be used to be inserted into another temporary table that would calculate the data for Profit and Loss Statement (For Manufacturing related Accounts only).</p>
  
  <p>In this case, the <code>acc_code</code> for Manufacturing accounts start from <code>7000/000</code> and separated/partitioned for each following <code>Exttype</code>. </p>
  
  <p>Eg: We start from the exttype of <code>MA</code> and based on its <code>acclevel</code> (could be 2 or more) until the next exttype.</p>
  
  <p>The idea is we get the manufacturing accounts by <code>SELECT</code> <code>FROM</code> <code>tmp_acc_list</code> <code>WHERE</code> <code>acc_code</code> <code>BETWEEN</code> <code>@start_acc_code</code> (7000/000 in this case) <code>AND</code> <code>@end_acc_code</code> (the data before the next exttype)</p>
  
  <ul>
  <li>I don't know what the exttype is, I'm still learning the tables.</li>
  </ul>
  
  <p>How do we create the <code>@end_acc_code</code> part out from this sample table?</p>