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  

search missing numbers



 
 
Thread Tools Display Modes
  #1  
Old September 11th, 2009, 08:53 PM posted to microsoft.public.access.queries
Todd
external usenet poster
 
Posts: 70
Default search missing numbers

How can I make a query to search for missing sequential numbers. Say I have
a field called assetid and the assetid numbers start with 00001 and go
through 10000. How can I make a query to do a search and show all numbers
that are not listed from the above range of numbers?
--
Todd
  #2  
Old September 11th, 2009, 09:17 PM posted to microsoft.public.access.queries
MGFoster
external usenet poster
 
Posts: 653
Default search missing numbers

Todd wrote:
How can I make a query to search for missing sequential numbers. Say I have
a field called assetid and the assetid numbers start with 00001 and go
through 10000. How can I make a query to do a search and show all numbers
that are not listed from the above range of numbers?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here's a query (changed to Access SQL) I got from an SQL Server
newsgroup:

SequenceTable is the table that is being searched for missing numbers.
Change the name to suit your set up. SeqNbr is the column (Field) being
tested - change to suit your set up.

SELECT LastSeqNbr
, NextSeqNbr
, LastSeqNbr + 1 As FirstAvail
, NextSeqNbr - 1 As LastAvail
, NextSeqNbr - (LastSeqNbr + 1) As NbrsAvail
FROM (
SELECT
(SELECT Nz(Max(Seq2.SeqNbr),0) As SeqNbr
FROM SequenceTable As Seq2
WHERE Seq2.SeqNbr Seq1.SeqNbr) As LastSeqNbr
, SeqNbr As NextSeqNbr
FROM SequenceTable As Seq1
) as A
WHERE NextSeqNbr - LastSeqNbr 1
ORDER BY LastSeqNbr

Resulting output

LastSeqNbr NextSeqNbr FirstAvail LastAvail NbrsAvail
0 10 1 9 9
103 105 104 104 1
107 114 108 113 6
116 129 117 128 12


HTH,
--
MGFoster:::mgf00 at earthlink decimal-point net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSqqwXYechKqOuFEgEQIq9gCg1JRpdCvC9W3DQMV2eRZqGA OO3T0AoOUx
OQPegvC5Hg7Km3ePxA7dvey0
=Hj9l
-----END PGP SIGNATURE-----
  #3  
Old September 11th, 2009, 09:23 PM posted to microsoft.public.access.queries
Todd
external usenet poster
 
Posts: 70
Default search missing numbers

I forgot to mention that I'm using access 2003 but the table I'm trying to
query is a linked table to an SQL 2005 dbase and the actual SQL column is
data type char(20) but when I view the design view in Access it is considered
text. All the assetid records are actual whole numbers but they start with
000001, 000002, 000003, etc.
--
Todd


"Todd" wrote:

How can I make a query to search for missing sequential numbers. Say I have
a field called assetid and the assetid numbers start with 00001 and go
through 10000. How can I make a query to do a search and show all numbers
that are not listed from the above range of numbers?
--
Todd

  #4  
Old September 11th, 2009, 10:16 PM posted to microsoft.public.access.queries
Todd
external usenet poster
 
Posts: 70
Default search missing numbers

Thanks! That did the trick.
--
Todd


"MGFoster" wrote:

Todd wrote:
How can I make a query to search for missing sequential numbers. Say I have
a field called assetid and the assetid numbers start with 00001 and go
through 10000. How can I make a query to do a search and show all numbers
that are not listed from the above range of numbers?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here's a query (changed to Access SQL) I got from an SQL Server
newsgroup:

SequenceTable is the table that is being searched for missing numbers.
Change the name to suit your set up. SeqNbr is the column (Field) being
tested - change to suit your set up.

SELECT LastSeqNbr
, NextSeqNbr
, LastSeqNbr + 1 As FirstAvail
, NextSeqNbr - 1 As LastAvail
, NextSeqNbr - (LastSeqNbr + 1) As NbrsAvail
FROM (
SELECT
(SELECT Nz(Max(Seq2.SeqNbr),0) As SeqNbr
FROM SequenceTable As Seq2
WHERE Seq2.SeqNbr Seq1.SeqNbr) As LastSeqNbr
, SeqNbr As NextSeqNbr
FROM SequenceTable As Seq1
) as A
WHERE NextSeqNbr - LastSeqNbr 1
ORDER BY LastSeqNbr

Resulting output

LastSeqNbr NextSeqNbr FirstAvail LastAvail NbrsAvail
0 10 1 9 9
103 105 104 104 1
107 114 108 113 6
116 129 117 128 12


HTH,
--
MGFoster:::mgf00 at earthlink decimal-point net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSqqwXYechKqOuFEgEQIq9gCg1JRpdCvC9W3DQMV2eRZqGA OO3T0AoOUx
OQPegvC5Hg7Km3ePxA7dvey0
=Hj9l
-----END PGP SIGNATURE-----

  #5  
Old September 16th, 2009, 02:04 PM posted to microsoft.public.access.queries
Todd
external usenet poster
 
Posts: 70
Default search missing numbers

Do you happen to know where you got the SQL code for the below script? I
tried to put it in the sql dbase where the actual table is located and I got
an error and I was just wondering how different the code was in sql as
opposed to access.
--
Todd


"MGFoster" wrote:

Todd wrote:
How can I make a query to search for missing sequential numbers. Say I have
a field called assetid and the assetid numbers start with 00001 and go
through 10000. How can I make a query to do a search and show all numbers
that are not listed from the above range of numbers?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here's a query (changed to Access SQL) I got from an SQL Server
newsgroup:

SequenceTable is the table that is being searched for missing numbers.
Change the name to suit your set up. SeqNbr is the column (Field) being
tested - change to suit your set up.

SELECT LastSeqNbr
, NextSeqNbr
, LastSeqNbr + 1 As FirstAvail
, NextSeqNbr - 1 As LastAvail
, NextSeqNbr - (LastSeqNbr + 1) As NbrsAvail
FROM (
SELECT
(SELECT Nz(Max(Seq2.SeqNbr),0) As SeqNbr
FROM SequenceTable As Seq2
WHERE Seq2.SeqNbr Seq1.SeqNbr) As LastSeqNbr
, SeqNbr As NextSeqNbr
FROM SequenceTable As Seq1
) as A
WHERE NextSeqNbr - LastSeqNbr 1
ORDER BY LastSeqNbr

Resulting output

LastSeqNbr NextSeqNbr FirstAvail LastAvail NbrsAvail
0 10 1 9 9
103 105 104 104 1
107 114 108 113 6
116 129 117 128 12


HTH,
--
MGFoster:::mgf00 at earthlink decimal-point net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSqqwXYechKqOuFEgEQIq9gCg1JRpdCvC9W3DQMV2eRZqGA OO3T0AoOUx
OQPegvC5Hg7Km3ePxA7dvey0
=Hj9l
-----END PGP SIGNATURE-----

 




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 10:08 PM.


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