title: How to check if the previous and next records are sequential in SQL
body: <p>I have a table which has columns (ID int, RECEIPT_BARCODE nvarchar(200),FK_CLOSURE bigint) </p>
  
  <pre><code>ID          RECEIPT_BARCODE          FK_CLOSURE  
  
  1           01020011304500190001    58100000010019
  2           01020011304500190002    58100000010019
  1           01020011404500200001    58100000010020
  2           01020011404500200002    58100000010020
  3           01020011404500200003    58100000010020
  1           01020011504500210001    58100000010021
  1           01020011604500220001    58100000010022
  1           01020011604500230001    58100000010023
  2           01020011604500230002    58100000010023
  1           01020011604500250001    58100000010025
  3           01020011604500250003    58100000010025
  </code></pre>
  
  <p>Our program is automatically inserting the sales into the table. This table is being inserted like;
  when FK_CLOSURE  up, ID is being set again to '1' (as you can see above) then it goes sequential as long as FK_CLOSURE doesnt change. When FK_CLOSURE change again, ID is set to '1'. </p>
  
  <p>So the problem is; sometimes our sale program works wrong and doest insert a sale however increase the ID value as you can see in the last row. In the last row it increased ID from 1 to 3, there is no 2... </p>
  
  <p>and i would like to report that kind of fails. I tried to use CURSOR but couldn't manage.
  Any suggestions ? </p>