I am trying to create a query that returns a list of clients that were in a placement at any point during a month. The SQL below will return the list for the previous month but I want to get the lists for each of the previous 12 months all in one query. I've thought about just making a query for each of the 12 months and appending them all to a table but wanted to see if there was a quicker way. Any ideas?
Code:
SELECT DISTINCTROW PCC_Vendor_Number.PCC_VNum, Placements.CRPCaseNum, DateSerial(Year(Date()),Month(Date())-1,1) AS [Month]
FROM Placements INNER JOIN PCC_Vendor_Number ON Placements.PCC_VNum = PCC_Vendor_Number.PCC_VNum
WHERE (((Placements.datAdmit)<=DateSerial(Year(Date()),Month(Date()),0)) AND ((Placements.datDischarge)>=DateSerial(Year(Date()),Month(Date())-1,1) Or (Placements.datDischarge) Is Null))
GROUP BY PCC_Vendor_Number.PCC_VNum, Placements.CRPCaseNum, DateSerial(Year(Date()),Month(Date())-1,1)
ORDER BY PCC_Vendor_Number.PCC_VNum;