at the moment I query my database to find all interactions within a certain date parameter. I also join that table with my InteractionAttendees then join it by TargetGroups table. InteractionAttendees tells me who attended the interaction, TargetGroup tells me about the person, if they are part of a target group such as aboriginal or francophone.
I'm having trouble setting my Aboriginal and Francophone columns. I want to set it to be true if there was any attendees that are in the TargetGroup Table.
select CONVERT(date, getdate()) as ActivityDate,
CASE when Type = 0 Then 'General'
when Type = 1 Then 'Activity'
else 'Task' End as Type,
CASE when Indepth = 0 Then 'False' else 'True' End as Indepth,
Subject,
Comments,
'false' as Aboriginal,
'false' as FrancoPhone,
'false' as Female,
'false' as Youth,
'false' as Other
from Sarnia.dbo.Interactions as X
full outer join sarnia.dbo.InteractionAttendees as Y on X.Id = Y.Interaction_Id
full outer join Sarnia.dbo.TargetGroups as Z on Y.Person_Id = Z.PersonId
where ActivityDate >= '2015-07-01' and ActivityDate <= '2015-09-30'
group by ActivityDate, Type, Indepth, Created, subject, comments
for example
Interaction Table
Id
1
Interaction Attendee Table
Id InteractionId PersonId
1 1 5
2 1 10
TargetGroups Table
Id PersonId TargetValue
1 5 Aboriginal
2 10 Francophone
So my resulted table would be
Activity Date Aboriginal Francophone
---- True True
May I ask how do I properly populate my target group columns.