Finding missing invoices

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My database has a a table and a field called "OrderID" which holds invoice
numbers in sequential order. Sometimes there is some invoices missing for
example there may be:
53591
53592
53593
53594
53596
And 53595 is missing, is there a way to find the numbers that are missing?
 
Try this:

SELECT YourTableName.OrderID
FROM YourTableName
WHERE (YourTableName.OrderID - (SELECT Max(T.OrderID)
FROM YourTableName AS T WHERE
T.OrderID < YourTableName.OrderID) <> 1
AND (SELECT Min(TT.OrderID)
FROM YourTableName AS TT) <> YourTableName.OrderID;
 
Back
Top