Numbering Records

  • Follow


I have a request to be able to sequentially number records in a query.  I 
have looked in the forum and found similar questions, but I guess I am not 
making the connection.  I have a table named, Cycle_Time, that I am running a 
query off of and the fields include Facility, Ord Num, Ord Line Num, Cycle 
Time.  I am after a result to group it by facility.  I am have an example 
below.

Facility   Ord Num  Ord Line Num  Cycle Time  Result I want
HK          1234         001                  10                1
HK          4567         003                    9                2
HK          7899         002                    8                3
JF           9874         003                  12                1
JF           5632         001                  11                2
JF           6543         002                  10                3

I would appreciate any help on coding this.  Thanks for all your help.
0
Reply Utf 1/28/2008 2:34:00 PM

Not exactly what you want, the result will be:

 Facility   Ord Num  Ord Line Num  Cycle Time  Result I want
 HK          1234         001                  10                1
 HK          4567         003                    9                2
 HK          7899         002                    8                3
 JF           5632         001                  11                1
 JF           6543         002                  10                2
 JF           9874         003                  12                3



with:



SELECT a.facility, a.ordNum, LAST(a.ordLine), LAST(a.cycle),  COUNT(*) as 
ResultIwant
FROM myTable AS a INNER JOIN myTable AS b
    ON a.facility = b.facility
    AND a.ordNum >= b.ordNum
GROUP BY  a.facility, a.ordNum



where you will have to replace the name myTable with the real name of your 
table (at two places).





Hoping it may help,
Vanderghast, Access MVP


"Keith S" <KeithS@discussions.microsoft.com> wrote in message 
news:6BEF7B42-D9A3-4E44-BA90-D71D3B6452C1@microsoft.com...
>I have a request to be able to sequentially number records in a query.  I
> have looked in the forum and found similar questions, but I guess I am not
> making the connection.  I have a table named, Cycle_Time, that I am 
> running a
> query off of and the fields include Facility, Ord Num, Ord Line Num, Cycle
> Time.  I am after a result to group it by facility.  I am have an example
> below.
>
> Facility   Ord Num  Ord Line Num  Cycle Time  Result I want
> HK          1234         001                  10                1
> HK          4567         003                    9                2
> HK          7899         002                    8                3
> JF           9874         003                  12                1
> JF           5632         001                  11                2
> JF           6543         002                  10                3
>
> I would appreciate any help on coding this.  Thanks for all your help. 


0
Reply Michel 1/28/2008 2:47:10 PM


You need a ranking subquery in your main query

SELECT Facility
, Ord Num
, Ord Line Num
, Cycle Time
, 1 + (SELECT Count(*)
FROM YourTable as Tmp
WHERE Tmp.Facility = YourTable.Facility
AND Tmp.[Cycle Time] > YourTable.[Cycle Time]) as Rank
FROM YourTable

In the query grid (Design view) in a new field "cell" enter the following 
(all on one line)
Rank: 1 + (SELECT Count(*) FROM YourTable as Tmp WHERE Tmp.Facility = 
YourTable.Facility AND Tmp.[Cycle Time] > YourTable.[Cycle Time])

Note that with a large set of records this typeof query can be slow.
-- 
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"Keith S" <KeithS@discussions.microsoft.com> wrote in message 
news:6BEF7B42-D9A3-4E44-BA90-D71D3B6452C1@microsoft.com...
>I have a request to be able to sequentially number records in a query.  I
> have looked in the forum and found similar questions, but I guess I am not
> making the connection.  I have a table named, Cycle_Time, that I am 
> running a
> query off of and the fields include Facility, Ord Num, Ord Line Num, Cycle
> Time.  I am after a result to group it by facility.  I am have an example
> below.
>
> Facility   Ord Num  Ord Line Num  Cycle Time  Result I want
> HK          1234         001                  10                1
> HK          4567         003                    9                2
> HK          7899         002                    8                3
> JF           9874         003                  12                1
> JF           5632         001                  11                2
> JF           6543         002                  10                3
>
> I would appreciate any help on coding this.  Thanks for all your help. 


0
Reply John 1/28/2008 2:54:55 PM

Thank you Michel, this is exactly what I need to finish a project.  I 
appreciate your time.

"Michel Walsh" wrote:

> Not exactly what you want, the result will be:
> 
>  Facility   Ord Num  Ord Line Num  Cycle Time  Result I want
>  HK          1234         001                  10                1
>  HK          4567         003                    9                2
>  HK          7899         002                    8                3
>  JF           5632         001                  11                1
>  JF           6543         002                  10                2
>  JF           9874         003                  12                3
> 
> 
> 
> with:
> 
> 
> 
> SELECT a.facility, a.ordNum, LAST(a.ordLine), LAST(a.cycle),  COUNT(*) as 
> ResultIwant
> FROM myTable AS a INNER JOIN myTable AS b
>     ON a.facility = b.facility
>     AND a.ordNum >= b.ordNum
> GROUP BY  a.facility, a.ordNum
> 
> 
> 
> where you will have to replace the name myTable with the real name of your 
> table (at two places).
> 
> 
> 
> 
> 
> Hoping it may help,
> Vanderghast, Access MVP
> 
> 
> "Keith S" <KeithS@discussions.microsoft.com> wrote in message 
> news:6BEF7B42-D9A3-4E44-BA90-D71D3B6452C1@microsoft.com...
> >I have a request to be able to sequentially number records in a query.  I
> > have looked in the forum and found similar questions, but I guess I am not
> > making the connection.  I have a table named, Cycle_Time, that I am 
> > running a
> > query off of and the fields include Facility, Ord Num, Ord Line Num, Cycle
> > Time.  I am after a result to group it by facility.  I am have an example
> > below.
> >
> > Facility   Ord Num  Ord Line Num  Cycle Time  Result I want
> > HK          1234         001                  10                1
> > HK          4567         003                    9                2
> > HK          7899         002                    8                3
> > JF           9874         003                  12                1
> > JF           5632         001                  11                2
> > JF           6543         002                  10                3
> >
> > I would appreciate any help on coding this.  Thanks for all your help. 
> 
> 
> 
0
Reply Utf 1/28/2008 3:07:01 PM

One last question about this, in my table it is sorted by Facility and Cycle 
Time.  I want it to number how it is sorted in the table.  Is there syntax to 
have it sort that way?  I have tried moving the fields around in the select 
statement and in the Group By.

Thanks again.

"Keith S" wrote:

> I have a request to be able to sequentially number records in a query.  I 
> have looked in the forum and found similar questions, but I guess I am not 
> making the connection.  I have a table named, Cycle_Time, that I am running a 
> query off of and the fields include Facility, Ord Num, Ord Line Num, Cycle 
> Time.  I am after a result to group it by facility.  I am have an example 
> below.
> 
> Facility   Ord Num  Ord Line Num  Cycle Time  Result I want
> HK          1234         001                  10                1
> HK          4567         003                    9                2
> HK          7899         002                    8                3
> JF           9874         003                  12                1
> JF           5632         001                  11                2
> JF           6543         002                  10                3
> 
> I would appreciate any help on coding this.  Thanks for all your help.
0
Reply Utf 1/28/2008 9:46:09 PM

This is a multi-part message in MIME format.

------=_NextPart_000_0E55_01C8624E.853037C0
Content-Type: text/plain;
	charset="Utf-8"
Content-Transfer-Encoding: quoted-printable

Try the following:

SELECT a.facility, a.cycle, LAST(a.ordLine), LAST(a.OrdNum),  COUNT(*) =
as=20
ResultIwant
FROM myTable AS a INNER JOIN myTable AS b
    ON a.facility =3D b.facility
    AND a.cycle>=3D b.cycle
GROUP BY  a.facility, a.cycle


Hoping it may help,
Vanderghast, Access MVP



"Keith S" <KeithS@discussions.microsoft.com> wrote in message =
news:39C7253A-2355-4235-9B05-50B554D2C739@microsoft.com...
> One last question about this, in my table it is sorted by Facility and =
Cycle=20
> Time.  I want it to number how it is sorted in the table.  Is there =
syntax to=20
> have it sort that way?  I have tried moving the fields around in the =
select=20
> statement and in the Group By.

------=_NextPart_000_0E55_01C8624E.853037C0
Content-Type: text/html;
	charset="Utf-8"
Content-Transfer-Encoding: quoted-printable

=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8">
<META content=3D"MSHTML 6.00.6000.16587" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>Try the following:</DIV>
<DIV>&nbsp;</DIV>
<DIV>SELECT a.facility, <STRONG>a.cycle</STRONG>, LAST(a.ordLine),=20
LAST(a.OrdNum),&nbsp; COUNT(*) as <BR>ResultIwant<BR>FROM myTable AS a =
INNER=20
JOIN myTable AS b<BR>&nbsp;&nbsp;&nbsp; ON a.facility =3D=20
b.facility<BR>&nbsp;&nbsp;&nbsp; AND a.<STRONG>cycle</STRONG>&gt;=3D=20
b.<STRONG>cycle</STRONG><BR>GROUP BY&nbsp; a.facility,=20
a.<STRONG>cycle</STRONG></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Hoping it may help,</DIV>
<DIV>Vanderghast, Access MVP</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>"Keith S" &lt;<A=20
href=3D"mailto:KeithS@discussions.microsoft.com">KeithS@discussions.micro=
soft.com</A>&gt;=20
wrote in message <A=20
href=3D"news:39C7253A-2355-4235-9B05-50B554D2C739@microsoft.com">news:39C=
7253A-2355-4235-9B05-50B554D2C739@microsoft.com</A>...</DIV>&gt;=20
One last question about this, in my table it is sorted by Facility and =
Cycle=20
<BR>&gt; Time.&nbsp; I want it to number how it is sorted in the =
table.&nbsp; Is=20
there syntax to <BR>&gt; have it sort that way?&nbsp; I have tried =
moving the=20
fields around in the select <BR>&gt; statement and in the Group=20
By.<BR></BODY></HTML>

------=_NextPart_000_0E55_01C8624E.853037C0--

0
Reply Michel 1/29/2008 1:11:15 PM

5 Replies
107 Views

(page loaded in 0.21 seconds)

Similiar Articles:
















7/20/2012 10:53:19 PM


Reply: