I am trying to run a query to pull the total amount of qualifying events grouped by event type and month. For example I need to know that there were 25 "LOSS_OF_COVERAGE_NON_PAYMENT" qualifying events in January, and 10 "LEAVE_OF_ABSENCE" qualifying events in January. I have tried various SQL select queries. I am not sure why the query below is returning an error that states
Invalid column name 'EventMonth'
My query:
SELECT
a.GroupID, c.employername,
MONTH(b.QualifyingEventDate) AS EventMonth,
b.QualifyingEventType
FROM
MST_MEMBER_DEMOGRAPHICS AS a
JOIN
DET_ENROLLMENT_DETAILS AS b ON a.BFUNIQUEID = b.BFUNIQUEID
JOIN
MST_EMPLOYER_GROUP_MASTER AS c ON a.groupid = c.groupid
WHERE
a.groupid = 'TESTClient'
AND QualifyingEventType <> 'NULL'
AND QualifyingEventDate BETWEEN '01/01/2019' AND '08/13/2019'
GROUP BY
b.QualifyingEventType, EventMonth
ORDER BY
EventMonth, a.groupid, b.QualifyingEventType