Return records from multiple date criteria

TyeReece

Board Regular
Joined
Aug 3, 2007
Messages
136
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;
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Make a query that pulls all data between today and the past 12 months.
in a form ,put start and end date text boxes, then They look like:
TxtStart =date
txtEnd=dateAdd("m",-12,txtStart)

Qry= select * from data where [dateFld] between forms!myForm!txtStart and forms!myForm!txtEnd
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,266
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top