Solved

Access Query to filter table by Highest Value found in two Fields + iif logic

Posted on 2008-10-08
3
629 Views
Last Modified: 2013-11-28
I have a table in Access with the following fields (see attachment 1):
ParentPart
Version
Route
Component
QtyPer

I would like to write a query using the logic of the following psuedocode:
If Version is null, then return each record for each "ParentPart" where the "Route" is the highest value for that "ParentPart", If Version is not null, then ignore the route and return each record for each "ParentPart" where the "Version" is the highest value for that "ParentPart".

Basically for each parent part I want to grab the entire row if the version number is the highest value in the entire table or if version is null if the route is the highest value.

The second attached file shows what the Output of the query would be for the query.

Thanks for the help







table.jpg
table2.jpg
0
Comment
Question by:Cubemaster
3 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22676003
Try with a derived table:
SELECT b1.*

FROM BOMTable b1 

INNER JOIN (SELECT ParentPart, Max(Version) AS maxVersion, Max(Route) AS maxRoute FROM BOMTable GROUP BY ParentPart) b2

ON b1.ParentPart = b2.ParentPart

AND (b1.Version = b2.maxVersion 

     OR (IsNull(b1.Version)=1 AND b1.Route = b2.maxRoute))

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

15 Experts available now in Live!

Get 1:1 Help Now