Solved

Access query - First keyword question

Posted on 2013-06-02
7
401 Views
Last Modified: 2013-06-02
Dear experts -
I have a table of milestones for each milestone of a project. I want to determine the EARLIEST INCOMPLETE record in this table.
What I've done so far:
Create a Subquery, sorting the results by project + date + descriptor.
I created a master query that invokes the subquery and uses the FIRST keyword to find the first occurrence for this project_ID. (I assumed that it was using the sort order built into the subquery.)
It is simply pulling the wrong information.
Any ideas?
Thanks!
0
Comment
Question by:terpsichore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 39214455
You'll need to add an autonumber column to the table like ID.

Then you query will  look something like this:

SELECT SubQ.project, SubQ.datefld, SubQ.descriptor
FROM (SELECT TableX.project, TableX.datefld, TableX.descriptor,  (select count(*) from tableX as x where x.project=tablex.project and x.datefld=tablex.datefld and x.ID<=tablex.ID) AS Seq
   FROM TableX
   WHERE descriptor = "Incomplete"
   ORDER BY TableX.project, TableX.datefld, TableX.descriptor, TableX.ID) SubQ
WHERE SubQ.Seq = 1

Open in new window

0
 

Author Comment

by:terpsichore
ID: 39214485
thanks - can you explain this a little more, and why this would work and why my version wouldn't, perhaps? THANK YOU
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39214518
Basically I'm creating a sequence number. And it is a good idea to learn how to do it as the First and Last keywords are unique to Access/JET SQL and nothing else.

I presume that the data is added to you table at random times. This puts them in order and only select the sequence number 1.

That is based on the idea you have an index on the project and datefld when you add the autonumber.
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:terpsichore
ID: 39214525
great - sorry to trouble, but one last question before i award you the points - we are migrating to sql server (and also need a consultant for that!) - should we use a different query? THANK YOU
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39214545
should we use a different query?

It is easier in MS SQL.

To get a sequence number you use the Row_Number or  Rank functions.
0
 

Author Closing Comment

by:terpsichore
ID: 39214617
Very perceptive, very thorough.
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39214812
Thanks.

Glad to be of assistance. May your days get brighter and brighter.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

734 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