DataBase - Identify missing numbers

Asked By Tara
20-Nov-09 01:50 PM
I have a table that uses a text field to store receipt numbers.  Currently I
use VAL to sort the numbers numerically.  Is there a way to identify which
numbers are missing out of the sequence?  For instance if my receipts start
at 1 and go through 10,000, but receipts 900 through 987 are missing, can I
get a query to show me that?

Thanks!
T100.NumField
(1)
T1000.Numfield
(1)
ReceiptNumber
(1)
MissingValues
(1)
ReceiptsTable
(1)
NumTable
(1)
TaraBy
(1)
CStr
(1)
  Jeff Boyce replied to Tara
20-Nov-09 02:41 PM
Tara

By "missing" I asssume you mean "should be in a list but is not"...

One way to do this is to have a list of what numbers SHOULD be listed, then
use the query wizard to construct an "unmatched" query between your list and
the SHOULD BE list to see which of the SHOULD BE values are not in your
list.

Or you could create a procedure that steps through the sequence numbers
one-by-one, looking for situations in which the next (expected) value is not
present, saving all those up, then displaying those after running through
your list.

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
  KARL DEWEY replied to Tara
20-Nov-09 03:35 PM
Try this --
WO8SEP09 is the table and Work is the number field.  The first query finds
the first missing number in a sequence and the second find the end of that
sequence.

first missing number of each sequence --
SELECT [Work]+1 AS Missing
FROM WO8SEP09 AS T
WHERE (((Exists (SELECT *       FROM WO8SEP09 T1       WHERE T1.[Work] =
T.[Work] + 1))=False));


SELECT [first missing number of each sequence].Missing AS Missing_Start,
(SELECT TOP 1 [XX].Work FROM WO8SEP09 AS [XX] WHERE [XX].Work > [first
missing number of each sequence].Missing ORDER BY [XX].Work)-1 AS Missing_End
FROM [first missing number of each sequence];

--
Build a little, test a little.
  John Spencer replied to Tara
20-Nov-09 03:41 PM
Construct a table with one number field and 10 records with the numbers 0 to 9.

Construct a query using that table multiple times to generate numbers from
zero to 10,000

SELECT CStr(T1.NumField + T10.NumField*10 + T100.NumField * 100 +
T1000.Numfield*1000) as NumString
FROM NumTable as T1, NumTable As t10, NumTable as T100, NumTable as T1000

Now you can use that and your store reciept table to do an unmatched query.

SELECT NumString as MissingValues
FROM QueryNumString LEFT JOIN [ReceiptsTable] as R
ON QueryNumString.NumString = R.[ReceiptNumber]
WHERE R.[ReceiptNumber] is Null

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
  Tara replied to Tara
20-Nov-09 03:55 PM
Thank you both for the suggestions!
"Tara" wrote:
Create New Account
help
DateTime, EndingDate DateTime; TRANSFORM First(PaymentAmount) AS FirstOfPaymentAmount SELECT ID, [LastName] & (", "+[FirstName]) AS Name, PaymentDate, ReceiptNumber, PaymentMethod FROM tblPaymentsReceived WHERE PaymentDate)> = BeginningDate And PaymentDate)< = EndingDate) AND ReceiptNumber Is Not Null GROUP BY ID, [LastName] & (", "+[FirstName]), PaymentDate, ReceiptNumber, PaymentMethod ORDER BY ReceiptNumber PIVOT Allocation; Any help would be greatly appreciated. Darrell Access Queries Discussions FirstOfPaymentAmount (1) Report 1) PaymentAmount (1) BeginningDate (1) PaymentMethod (1) ReceiptNumber (1) PaymentDate (1) EndingDate (1) Hi Darrell, If you simply want to ensure that all
Database.Tables(iTableNo).SetLogOnInfo ServerName, Database, UserName, Password Next iTableNo Report.DiscardSavedData Report.ParameterFields.GetItemByName("ReceiptNumber").AddCurrentValue ReceiptNumber Report.PrintOut False, 1 Regards, - - Mohammad R. Daoud MCP, MCBMSP, MCTS, MCBMSS Mob: +962 - 79
what I just described: CREATE TRIGGER feedMyOtherSystem ON POP30310 AFTER INSERT AS DECLARE @myReceipts table ( @ReceiptNumber char(20), @VendorID char(20), @ItemNumber char(20), @Order int, @Quantity numeric(19, 5), @anyOtherColumn. . . ) INSERT @myReceipts(@ReceiptNumber, @VendorID, @ItemNumber, @Order, @Quantity, @anyOtherColumn. . .) SELECT i.RCPTNMBR, i.VENDORID, i.ITEMNMBR, i.ORD, b