G
Guest
Hello,
I am having some trouble with a query. It is basically a query that is fed
to a report that shows what clients need to be followed up with in the next
week, by the Next Action date. It is based off of 3 tables, and has several
fields. The problem I am having is that it is not showing the last record for
each client. It is for some of them, but not for all! It seems to show
duplicates only when there are 2 different Next Action dates within the same
week. For example, I have a client that I am supposed to follow up with
tomorrow, so the Next Action Date is 3/1/06. However, the client actually
calls me today, and says to follow up with him next week. So the next follow
up record added has a Next Action Date of 3/6/06. Instead of now just showing
that new record, the query now STILL shows that the client needs to be
followed up with on 3/1/06 AND also on 3/6/06. So it is showing both records,
instead of just the last one. (Obviously this can get confusing, as I work
with a lot of clients daily, and can forget whether I have followed up with
them already or not -- this is the point of the query in the first place!) I
am using the Max function. The query is below:
SELECT Max(Events.[Next Action Date]) AS [MaxOfNext Action Date],
Contacts.First, Contacts.Last, Contacts.[Business Phone], Contacts.Extension,
Contacts.[Mobile Phone], Contacts.[Home Phone], Contacts.[Email Address],
Contacts.[Last Appointment Date], Last(Events.[Notes/Outcome]) AS
[LastOfNotes/Outcome], Last(Events.[Next Action]) AS [LastOfNext Action],
Tracking.Notes
FROM (Contacts INNER JOIN Events ON Contacts.ClientID = Events.ClientID)
INNER JOIN Tracking ON Contacts.ClientID = Tracking.ClientID
GROUP BY Contacts.First, Contacts.Last, Contacts.[Business Phone],
Contacts.Extension, Contacts.[Mobile Phone], Contacts.[Home Phone],
Contacts.[Email Address], Contacts.[Last Appointment Date], Tracking.Notes,
Events.NotesID, Contacts.ClientID
HAVING (((Max(Events.[Next Action Date])) Between Date() And
DateAdd("d",7,Date())))
ORDER BY Max(Events.[Next Action Date]);
As I was going through posts on here, trying to find the answer to the
problem, I saw several suggestions to make a Max query separately, with just
the ID and Date field that I wanted the Max of, and then join it to the other
tables in a new query. I tried that too. It is returning exactly the same
records as the one above, with exactly the same problem. This one is listed
below:
SELECT Contacts.ClientID, Events.NotesID, Contacts.First, Contacts.Last,
Contacts.[Business Phone], Contacts.Extension, Contacts.[Mobile Phone],
Contacts.[Home Phone], Contacts.[Email Address], Events.[Notes/Outcome],
Events.[Next Action], Tracking.Notes, [Max Query].[MaxOfNext Action Date]
FROM (Contacts INNER JOIN (Events INNER JOIN [Max Query] ON (Events.NotesID
= [Max Query].NotesID) AND (Events.[Next Action Date] = [Max
Query].[MaxOfNext Action Date])) ON Contacts.ClientID = Events.ClientID)
INNER JOIN Tracking ON Contacts.ClientID = Tracking.ClientID;
And here is the Max Query:
SELECT Events.NotesID, Max(Events.[Next Action Date]) AS [MaxOfNext Action
Date]
FROM Events
GROUP BY Events.NotesID
HAVING (((Max(Events.[Next Action Date])) Between Date() And
DateAdd("d",7,Date())))
ORDER BY Max(Events.[Next Action Date]);
Any ideas, anyone?
Thanks!
Rose.
I am having some trouble with a query. It is basically a query that is fed
to a report that shows what clients need to be followed up with in the next
week, by the Next Action date. It is based off of 3 tables, and has several
fields. The problem I am having is that it is not showing the last record for
each client. It is for some of them, but not for all! It seems to show
duplicates only when there are 2 different Next Action dates within the same
week. For example, I have a client that I am supposed to follow up with
tomorrow, so the Next Action Date is 3/1/06. However, the client actually
calls me today, and says to follow up with him next week. So the next follow
up record added has a Next Action Date of 3/6/06. Instead of now just showing
that new record, the query now STILL shows that the client needs to be
followed up with on 3/1/06 AND also on 3/6/06. So it is showing both records,
instead of just the last one. (Obviously this can get confusing, as I work
with a lot of clients daily, and can forget whether I have followed up with
them already or not -- this is the point of the query in the first place!) I
am using the Max function. The query is below:
SELECT Max(Events.[Next Action Date]) AS [MaxOfNext Action Date],
Contacts.First, Contacts.Last, Contacts.[Business Phone], Contacts.Extension,
Contacts.[Mobile Phone], Contacts.[Home Phone], Contacts.[Email Address],
Contacts.[Last Appointment Date], Last(Events.[Notes/Outcome]) AS
[LastOfNotes/Outcome], Last(Events.[Next Action]) AS [LastOfNext Action],
Tracking.Notes
FROM (Contacts INNER JOIN Events ON Contacts.ClientID = Events.ClientID)
INNER JOIN Tracking ON Contacts.ClientID = Tracking.ClientID
GROUP BY Contacts.First, Contacts.Last, Contacts.[Business Phone],
Contacts.Extension, Contacts.[Mobile Phone], Contacts.[Home Phone],
Contacts.[Email Address], Contacts.[Last Appointment Date], Tracking.Notes,
Events.NotesID, Contacts.ClientID
HAVING (((Max(Events.[Next Action Date])) Between Date() And
DateAdd("d",7,Date())))
ORDER BY Max(Events.[Next Action Date]);
As I was going through posts on here, trying to find the answer to the
problem, I saw several suggestions to make a Max query separately, with just
the ID and Date field that I wanted the Max of, and then join it to the other
tables in a new query. I tried that too. It is returning exactly the same
records as the one above, with exactly the same problem. This one is listed
below:
SELECT Contacts.ClientID, Events.NotesID, Contacts.First, Contacts.Last,
Contacts.[Business Phone], Contacts.Extension, Contacts.[Mobile Phone],
Contacts.[Home Phone], Contacts.[Email Address], Events.[Notes/Outcome],
Events.[Next Action], Tracking.Notes, [Max Query].[MaxOfNext Action Date]
FROM (Contacts INNER JOIN (Events INNER JOIN [Max Query] ON (Events.NotesID
= [Max Query].NotesID) AND (Events.[Next Action Date] = [Max
Query].[MaxOfNext Action Date])) ON Contacts.ClientID = Events.ClientID)
INNER JOIN Tracking ON Contacts.ClientID = Tracking.ClientID;
And here is the Max Query:
SELECT Events.NotesID, Max(Events.[Next Action Date]) AS [MaxOfNext Action
Date]
FROM Events
GROUP BY Events.NotesID
HAVING (((Max(Events.[Next Action Date])) Between Date() And
DateAdd("d",7,Date())))
ORDER BY Max(Events.[Next Action Date]);
Any ideas, anyone?
Thanks!
Rose.