Max Query with 2 Tables Problem

N

nataqe

I am attempting to return key records from 2 linked tables based on the
Maximum negative number returned from a DateDiff calculation.

Tables (linked on [Acct])

Table 1: T_Issue Table 2: T_Results
Acct Acct
UnitNo ResultNo
IssueDT CollectDT
Result

This first query returns:
-All [UnitNo] records from the T_Issue table
-The associated [ResultNo] records from the T_Results table where the DateDiff
is a negative number.
-The results of the DateDiff calculation

Query#1: Qtime
SELECT [T_Issue].[UnitNo], DateDiff("h",[IssueDT],[CollectDT]) AS LabTime,
[Lab Results].[ResultNo]
FROM (([T_Results] RIGHT JOIN [T_Issue] ON [T_Results].Account =
[T_Issue].Account)
WHERE (((DateDiff("h",[IssueDT],[CollectDT]))<0))
ORDER BY [T_Issue].[UnitNo], DateDiff("h",[IssueDT],[CollectDT]) DESC;

The second Query attempts to return the records associated with the Max
[LabTime] calculated field, grouped by [UnitNo].
However, as written, no results are returned. I have also tried to include
the Max and DateDiff in the first Query without success.

Query #2: Qmax
SELECT Qtime.[UnitNo], Qtime.LabTime, Qtime.[ResultNo]
FROM Qtime
WHERE (((Qtime.LabTime) In (SELECT Max([Qtime].[ResultNo]) AS MaxLabTime
FROM [Qtime]
GROUP BY [Qtime].[UnitNo])));

I sincerely appreciate any help offered.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top