-----Original Message-----
mike said:
Marshall, Thanks for hanging in there on this. Learning
how to do this is going to be a real help. Looks like I'm
basically there except for one exception. It's definately
counting days between orders which is GREAT,
I sort of cheated on the date calculation. It won't make a
difference in a strictly Access/Jet database, but to be
rigorous I shouldn't just subtract the two dates, but use
the DateDiff function instead.
but it looks
like it's not including all the records from the data
source. There are 189 records in
qryCourseLocationAccountsOrders. When I was grouping on
[Customer Name] there were 109 records showing up in the
query's results and when I group by SAPNumber as shown
below, I get 53 records. Do you see something in my code
that would limit the records returned? Thanks again. This
is VERY helpful!
I don't see a GROUP BY clause in the query below. Are you
saying that qryCourseLocationAccountsOrders is a GROUP BY
query? If so, it will only return records with unique
values in the grouped fields. How does the number of
records in the final query compare to the number of records
returned by qryCourseLocationAccountsOrders when it is
grouped by the SAPNumber field?
Maybe what you mean by grouped is that you're restricting
the subquery's latest date to SAPNumber instead of customer.
If so, it sounds like a good idea, but I don't know enough
about what you're doing to understand the implications of
this change to knw for sure. Regardless, I don't see how
this could affect the number of records returned by the
query.
The record source qryCourseLocationAccountsOrders is in
the query's design view and its alias goes by the same
name. Do I have to change the alias to X?
No, definitely not X, we're using X in the subquery. The
way I had it originally, the alias would have been set to T.
SAPNumber is the customer account number and
DollarsShipped is just how much the order was for.
Sometimes account names can be the same so I'm actually
doing this by account number which I should have done in
the example. Sorry about that. This is what I have:
SELECT qryCourseLocationAccountsOrders.SAPNumber,
qryCourseLocationAccountsOrders.[Customer Name],
qryCourseLocationAccountsOrders.InvoiceDate,
qryCourseLocationAccountsOrders.DollarsShipped,
qryCourseLocationAccountsOrders.InvoiceDate-(SELECT Max
(X.InvoiceDate)
FROM qryCourseLocationAccountsOrders AS X
WHERE X.InvoiceDate <
qryCourseLocationAccountsOrders.InvoiceDate AND X.
[SAPNumber] = qryCourseLocationAccountsOrders. [SAPNumber])
AS DaysElapsed
FROM qryCourseLocationAccountsOrders
ORDER BY qryCourseLocationAccountsOrders.SAPNumber,
qryCourseLocationAccountsOrders.InvoiceDate;