Reputation: 23
I'm doing a little project for school is sql. I'm using MS Access as my database engine.
I'm trying to calculate and update Project Phases with the real end date of a phase by the last real end date of an assignment in that phase. This query return me a prompt that ask me to enter a value for "meet.PhaseId".
UPDATE ProjectPhases
SET RealEndDate = (SELECT MAX(asgn.RealEndDate) AS RealEndDate
FROM Assignments AS asgn
INNER JOIN
(
Meetings AS meet
INNER JOIN ProjectPhases
ON meet.PhaseId = ProjectPhases.PhaseId
)
ON asgn.MeetingId = meet.MeetingId
WHERE meet.PhaseId = ProjectPhases.PhaseId
vAND asgn.RealEndDate IS NOT NULL)
WHERE meet.PhaseId = ProjectPhases.PhaseId;
Upvotes: 2
Views: 421
Reputation: 107652
Consider saving your aggregate query in a separate query and then use the domain aggregate, DLookUp()
in the update query. In MS Access SQL (unlike other dialects), update queries must maintain the updateable condition (or non read-only) which rules out use of aggregate queries.
SELECT query (no ProjectPhases join)
SELECT meet.PhaseId, MAX(asgn.RealEndDate) AS MaxRealEndDate
FROM Assignments AS asgn
INNER JOIN Meetings AS meet
ON asgn.MeetingId = meet.MeetingId
WHERE asgn.RealEndDate IS NOT NULL
GROUP BY meet.PhaseId
UPDATE query
UPDATE ProjectPhases p
SET p.RealEndDate = DLookUp("MaxRealEndDate", "myaggQuery", "PhaseId=" & p.PhaseId)
Alternatively, you might consider a nested domain aggregate to avoid the saved aggregate query:
UPDATE ProjectPhases p
SET p.RealEndDate = DMax("RealEndDate", "Assignments", "MeetingId=" &
DLookUp("MeetingId", "Meetings", "PhaseId=" & p.PhaseId) &
" AND RealEndDate IS NOT NULL")
Upvotes: 2
Reputation: 55841
You don't select meet.PhaseId from your subquery, thus no PhaseId exists to filter on.
It is often easier to build your query step by step using the GUI designer.
Upvotes: 0