title: SQL to Exclude a Value from a Sequence
body: <p>I have this code which I am using to find the next available Number in a Sequence. For example here is the data:</p>
  
  <pre><code>YEBX0001
  YEBX0002
  YEBX0003
  YEBXTEMP - This is the Problem in the Source Data.
  </code></pre>
  
  <p>The Query below returns </p>
  
  <pre><code>NULL
  YEBX003
  YEBX002
  YEBX001
  </code></pre>
  
  <p>How can I change my below query to exclude the YEBXTEMP value? as this is what is causing the Null as its not a numerical value within the sequence.</p>
  
  <p>Code:</p>
  
  <pre><code> select concat(left(mmitno,4),concat(repeat('0', 4-length(trim(RIGHT(TRIM
   (MMITNO),4)+0 ))),trim(RIGHT(TRIM(MMITNO),4)+0 ))) FROM MITMAS 
   WHERE MMITNO LIKE CONCAT(LEFT('YEBX0001',4),'%') and mmitty in (95,96) 
   ORDER BY MMITNO DESC
  </code></pre>