title: Get next available number from specific available range of numbers
body: <p>In my system I have to provide the next available number to a new customer; this number will be used as an account number. Sometimes I will have to change the range of available numbers if the particular account numbers are not available anymore.</p>
  
  <p>So..</p>
  
  <p>Table 1 holds customers and their account number:</p>
  
  <pre><code>Customer1 | 210314
  Customer2 | 210313
  Customer3 | 210312
  </code></pre>
  
  <p>Table 2 holds the range of account numbers to choose from:</p>
  
  <pre><code>StartNumber | 210300
  EndNumber   | 210452
  </code></pre>
  
  <p>I want to be able to select the next available number <code>(Max(accountnumber)+1)</code> and check if it is in the range of the number series in Table 2. In this case it would be 210315, but if I were to change the number series in Table 2, for example, to</p>
  
  <pre><code>StartNumber | 220000
  EndNumber   | 220999
  </code></pre>
  
  <p>it would then give 220001 as a next available number. </p>
  
  <p>Could someone give me an example of solution and sorry for the long description :)</p>