From: (e-mail address removed) (Michael Cheng)
Date: Mon, 22 Mar 2004 04:15:43 GMT
Subject: RE: Counter in a Query
Newsgroups: microsoft.public.access.queries
Hi, Dale
Thanks for posting in the community. From your description, I understand
that you would like to have a record number on each row and do not want to
use a table with one column for the counter.
MVP John got the right answer and I supposed for three primary fields you
would better use the query like this:
(supposing p1,p2,p3 are three primary fields in yourTable)
select yourTable.*, count(SELECT Count(*) FROM yourTable As T2 WHERE T2.p1
<=yourTtable.p1 and T2.p2 <=yourTable.p2 and T2.p3 <=yourTable.p3) as
RowNumber
from yourTable
order by p1,p2,p3
(what's more, you could change the sequence in "order by" to customize your
own order)
and you can use the query below to get the max number of you row in the
yourTable:
select max(rownumber) as MaxRowNumber
from (select yourTable.*,count(SELECT Count(*) FROM yourTable As T2 WHERE
T2.p1
<=yourTable.p1 and T2.p2 <=yourTable.p2 and T2.p3 <=yourTable.p3) as
rownumber
from yourTable)
Moreover, I found a Knowledge Base for you,
ACC2000: How to Rank Records Within a Query
http://support.microsoft.com/?id=208946
which lists three examples to show you how to rank records within a query
Hope these help.If you still have questions about it, please feel free to
post message here and I am glad to help.
Sincerely, yours
Michael Cheng
Microsoft Online Partner Support
************************************************
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.