I'm receiving this error: An aggregate cannot appear in an ON clause unless it is in a subquery contained in a HAVING clause or select list, and the column being aggregated is an outer reference.
I'm unaware of how to fix this, please help.
set datefirst 2
select [Table 2].[Active_Headcount]
, DATEADD(DD, 7 - (DATEPART(DW, MIN([Table 1].[Term Date]))), MIN([Table 1].[Term Date])) as EndOfWeek
, COUNT(*) as TermsPerWeek
from [Table 1]
left join [Table 2]
on (DATEADD(DD, 7 - (DATEPART(DW, MIN([Table 1].[Term Date]))), MIN([Table 1].[Term Date]))) = [Table 2].[WeekDate]
where [Table 1].[Term Date] not like 'null'
and (
[Table 1].[Term Date] like '%2016%'
or [Table 1].[Term Date] like '%2017%'
)
group by DATEPART(WEEK, [Table 1].[Term Date])
, [Table 2].[Active_Headcount]
order by EndOfWeek asc;
Active_Headcountto[Table 1].Active_Headcount.) Thanks! - Ben Gribaudo