title: How can you find the first break in a sequence of integer numbers?
body: <p>Imagine you have the following Table:</p>
  
  <pre><code>create table #myvalues(mykey int primary key)
  </code></pre>
  
  <p>You also have the following values:</p>
  
  <pre><code>insert into #myvalues(mykey) values(1)
  insert into #myvalues(mykey) values(2)
  insert into #myvalues(mykey) values(4)
  insert into #myvalues(mykey) values(5)
  insert into #myvalues(mykey) values(6)
  insert into #myvalues(mykey) values(8)
  insert into #myvalues(mykey) values(10)
  insert into #myvalues(mykey) values(11)
  insert into #myvalues(mykey) values(12)
  insert into #myvalues(mykey) values(15)
  insert into #myvalues(mykey) values(17)
  insert into #myvalues(mykey) values(20)
  </code></pre>
  
  <p>You also have a current value:</p>
  
  <pre><code>declare @currentvalue int
  
  select @currentvalue = 5
  </code></pre>
  
  <p>I want to find the first break in this sequence that occurs after the @currentvalue. In this case the answer would be 7. </p>
  
  <p>I could use a table variable and spin throught the records using a while loop, but there must be a better way. </p>
  
  <p>Any suggestions?</p>