A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Identify missing numbers



 
 
Thread Tools Display Modes
  #1  
Old November 20th, 2009, 06:50 PM posted to microsoft.public.access.queries
Tara
external usenet poster
 
Posts: 269
Default Identify missing numbers

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!
  #2  
Old November 20th, 2009, 07:41 PM posted to microsoft.public.access.queries
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default Identify missing numbers

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.

"Tara" wrote in message
...
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!



  #3  
Old November 20th, 2009, 08:35 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Identify missing numbers

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.


"Tara" wrote:

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!

  #4  
Old November 20th, 2009, 08:41 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Identify missing numbers

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 wrote:
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!

  #5  
Old November 20th, 2009, 08:55 PM posted to microsoft.public.access.queries
Tara
external usenet poster
 
Posts: 269
Default Identify missing numbers

Thank you both for the suggestions!
"Tara" wrote:

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!

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:47 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.