S
stephen.belyea
I want to thank both John Vinson and John Spencer for help on my
previous "Max Date" problem. The final solution was to use the
following SQL:
qryInspectionLatest
SELECT tblInspection.PropSiteName, Max(tblInspection.InspDate) AS
LatestInspDate
FROM tblInspection
GROUP BY PropSiteName;
Then join *this* query to tblProperty:
SELECT tblProperty.PropSiteName, tblProperty.PropStreet,
qryInspectionLatest.LatestInspDate
FROM tblProperty
LEFT JOIN qryInspectionLatest
ON qryInspectionLatest.PropSiteName = tblProperty.PropSiteName;
Now, however, I have a new problem. Per the revisions done by my boss,
I now need to add a couple of fields into the query (which need to
appear on the final report). These fields all reside in tblInspection.
InspRequestedOn
InspRequiredOn
InspResponseDueBy
InspCompletedOn
InspRepairsBy
InspRepairsCompletedOn
InspComplete?
(the first six are Date/Time in Short Date format, InspRecordComplete
is a Yes/No).
tblInspection is related to tblProperty by the field AutoIDProperty.
I attempted to do something similar to what worked last time, by doing
a join between the tblProperty and tblInspection, including all
records from tblProperty and only those from tblInspection where the
joined fields were equal. This is what my SQL looks like:
SELECT tblInspection.AutoIDProperty, tblProperty.PropSiteName,
Max(tblInspection.InspRequestedOn) AS MaxOfInspRequestedOn,
tblInspection.InspResponseDueBy, tblInspection.InspRequiredOn,
tblInspection.InspCompletedOn, tblInspection.InspRepairsBy,
tblInspection.InspRepairsCompletedOn, tblInspection.[InspComplete?]
FROM tblProperty LEFT JOIN tblInspection ON tblProperty.AutoIDProperty
= tblInspection.AutoIDProperty
GROUP BY tblInspection.AutoIDProperty, tblProperty.PropSiteName,
tblInspection.InspResponseDueBy, tblInspection.InspRequiredOn,
tblInspection.InspCompletedOn, tblInspection.InspRepairsBy,
tblInspection.InspRepairsCompletedOn, tblInspection.[InspComplete?]
ORDER BY Max(tblInspection.InspRequestedOn);
When I run this query, however, I get an error that says "no current
record". When I run this query without doing a join, I only get the
records that have dates recorded.
What I want to do is the same as last time - have all properties
listed, even if they have not been inspected yet. I'd really
appreciate any help you guys/gals could provide - I've been trying to
figure this out for a few hours now, and am just getting more
confused.
Thanks!
previous "Max Date" problem. The final solution was to use the
following SQL:
qryInspectionLatest
SELECT tblInspection.PropSiteName, Max(tblInspection.InspDate) AS
LatestInspDate
FROM tblInspection
GROUP BY PropSiteName;
Then join *this* query to tblProperty:
SELECT tblProperty.PropSiteName, tblProperty.PropStreet,
qryInspectionLatest.LatestInspDate
FROM tblProperty
LEFT JOIN qryInspectionLatest
ON qryInspectionLatest.PropSiteName = tblProperty.PropSiteName;
Now, however, I have a new problem. Per the revisions done by my boss,
I now need to add a couple of fields into the query (which need to
appear on the final report). These fields all reside in tblInspection.
InspRequestedOn
InspRequiredOn
InspResponseDueBy
InspCompletedOn
InspRepairsBy
InspRepairsCompletedOn
InspComplete?
(the first six are Date/Time in Short Date format, InspRecordComplete
is a Yes/No).
tblInspection is related to tblProperty by the field AutoIDProperty.
I attempted to do something similar to what worked last time, by doing
a join between the tblProperty and tblInspection, including all
records from tblProperty and only those from tblInspection where the
joined fields were equal. This is what my SQL looks like:
SELECT tblInspection.AutoIDProperty, tblProperty.PropSiteName,
Max(tblInspection.InspRequestedOn) AS MaxOfInspRequestedOn,
tblInspection.InspResponseDueBy, tblInspection.InspRequiredOn,
tblInspection.InspCompletedOn, tblInspection.InspRepairsBy,
tblInspection.InspRepairsCompletedOn, tblInspection.[InspComplete?]
FROM tblProperty LEFT JOIN tblInspection ON tblProperty.AutoIDProperty
= tblInspection.AutoIDProperty
GROUP BY tblInspection.AutoIDProperty, tblProperty.PropSiteName,
tblInspection.InspResponseDueBy, tblInspection.InspRequiredOn,
tblInspection.InspCompletedOn, tblInspection.InspRepairsBy,
tblInspection.InspRepairsCompletedOn, tblInspection.[InspComplete?]
ORDER BY Max(tblInspection.InspRequestedOn);
When I run this query, however, I get an error that says "no current
record". When I run this query without doing a join, I only get the
records that have dates recorded.
What I want to do is the same as last time - have all properties
listed, even if they have not been inspected yet. I'd really
appreciate any help you guys/gals could provide - I've been trying to
figure this out for a few hours now, and am just getting more
confused.
Thanks!