I have one table that has a list of people, each with their own 'Role'.
I need to cycle through this people list, selecting people with the role of 'Attendee' and count how many times they appear in a field of another table 'Events'
In the Events table, I have a field (Attendees) that contains a list of names (delimited by carriage return)
I want to end up with a list of names with the # of times they were found in the Attendee fields in Events.
PeopleTable [Name],[Role]
Names with Role= 'Attendee'
Name1
Name2
name3
Name4
EventsTable [Company],[Date],[Attendees]
Record 1
Name2
Name3
Record 2
Name1
Name2
Name4
Record 3
Name1
Name2
Name3
I want to end up with
Name1 2
Name2 3
Name3 2
Name4 1
Code:
SELECT Count(*)
FROM [Events],[People]
WHERE (([Events].[EventDate] >= Date()) AND (InStr([Events].[Attendees],[People].[Name])>0))
IN
(
SELECT [People.Name]
FROM [People]
WHERE ([People].[Role] = "Attendee")
)
ORDER BY [People].[Name];
Or
Code:
SELECT [People.Name]
FROM [People]
WHERE ([People].[Role] = "Attendee")
IN
(
SELECT Count(*)
FROM [Events],[People]
WHERE (([Events].[EventDate] >= Date()) AND (InStr([Events].[Attendees],[People].[Name])>0))
)
ORDER BY [People].[Name];