Solved

Access Query Sequential Numbering (After a sort)

Posted on 2007-11-20
5
599 Views
Last Modified: 2008-02-01
I have a simple query that summarizes sales by region and sorts the results in decending order.

I end up with a list of sales regions greatest to smallest (with counts of stores).

What I then need to do is make a new table that ranks these regions 1 to whatever, highest volume to lowest.
SELECT tdataStores.StrDMACity AS DMA, Sum([TblFY07-VolAndPen].FY07Vol) AS FY07_Vol, Count(tdataStores.StrID) AS Stores

FROM tdataStores INNER JOIN [TblFY07-VolAndPen] ON tdataStores.StrID = [TblFY07-VolAndPen].StrId

GROUP BY tdataStores.StrDMACity

ORDER BY Sum([TblFY07-VolAndPen].FY07Vol) DESC;

Open in new window

0
Comment
Question by:kb1esx
  • 3
5 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 20321460
see this link
How to Rank Records Within a Query
http://support.microsoft.com/?kbid=208946
0
 
LVL 18

Accepted Solution

by:
jmoss111 earned 500 total points
ID: 20321724
You could build a function
declare var
Dim Cntr as Integer
set value
Cntr = 1

Function VolCntr(x)
VolContr = Cntr
Cntr = Cntr + 1
End Function

A make table query

SELECT VolCntr ([FY07Vol]) AS Rank, etc, etc INTO MyRankTable FROM TableInYourExample
0
 
LVL 18

Expert Comment

by:jmoss111
ID: 20321733
VolCntr = Cntr
0
 

Author Comment

by:kb1esx
ID: 20321897
What was the second post for jmoss111?
0
 
LVL 18

Expert Comment

by:jmoss111
ID: 20322469
Statement under Function was misspelled s/b VolCntr was VolContr
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now