Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to locate records within Date Range 2

Status
Not open for further replies.

Accel45

Technical User
Jul 7, 2004
83
US
I have a database which tracks persons within a program. The length of the program is not fixed.

tblPerson has fields for demographic information as well as a program startdate field and a program enddate field.

I am attempting to create a query that retrieves records that fall within a given year.
For instance: What people were in the program for even 1 day during 2007?

The problem I’m having is with those records that have start dates before 2007 and end dates after 2007 (or no end date yet) but were in the program during 2007.

Any help or suggestions on how to retrieve the records would be appreciated.

Thanks
Accel45


 

How about...
Code:
WHERE StartDate Between #01/01/2007# And #12/31/2007#
OR EndDate Between #01/01/2007# And #12/31/2007#
OR (StartDate < #01/01/2007# AND EndDate > #12/31/2007#)
OR (StartDate < #01/01/2007# AND IsNull(EndDate))
Note: not tested


Randy
 
You can also use the complement of those included in the period.

Code:
SELECT tblDates.dtmStart, 
tblDates.dtmEnd 
FROM tblDates
WHERE NOT (((tblDates.dtmStart)>#12/31/2007#) OR ((nz([dtmEnd],#12/31/2007#))<#1/1/2007#));

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top