Re: Access query to return items free between two user input dates
- From: John Spencer <spencer@xxxxxxxxxx>
- Date: Sun, 19 Oct 2008 08:45:41 -0400
I realized AFTER I posted that the solution I proposed will only find resources if they have been used at least once.
I think you could use the basic query as a subquery in a where clause
SELECT Y.*
FROM YourTable as Y
WHERE Y.ResourceID NOT IN
(
SELECT Y2.ResourceID
FROM YourTable AS Y2
WHERE Y2.StartDate < = [Enter End Date]
And Y2.EndDate >= [Enter End Date])
Or build an unmatched query using your table and a saved query that is the where clause above.
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
John Spencer wrote:
The simplest way I can think of is the following. Test it and see if it gives your the desired results..
Parameters [Enter Begin Date] DateTime, [Enter End Date] DateTime;
SELECT Y.*
FROM YourTable AS Y
WHERE Not(Y.StartDate < = [Enter End Date]
And Y.EndDate >= [Enter End Date])
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
angel75 wrote:Hi, I am setting up loans database with a table holding all the dates that items are going in/out. I want to be able to ask user for the dates and search the table for an item which is free between the two dates.
eg phone 2 is booked on 1/11, so when I enter 1/11 as start and end date I want it to bring back phone 1/3/4. It is excluding the one entry where phone 2 is booked on that day, although it brings back all other entries for phone 2, and its also bringing back phone 1/3/4 future bookings, which is correct.
I am using Not Between StartDate and EndDate. What else do I need to do to ensure if its checked phone 1 and its booked to exclude that phone altogether? I am not good with SQL so want to keep it simple if possible.
SchedId ResourceId StartDate EndDate User Booked CheckedOut Completed
1 PHONE1 15-Jan-08 15-Jan-08 Sarah yes
2 PHONE1 10-Sep-08 12-Sep-08 Vicki yes
5 PHONE2 13-Oct-08 14-Oct-08 Fred yes
4 PHONE2 17-Oct-08 17-Oct-08 John yes yes no
3 PHONE1 20-Oct-08 20-Oct-08 Steve yes no
15 PHONE2 01-Nov-08 16-Nov-08 Jack yes no
11 PHONE2 19-Nov-08 25-Nov-08 Steve yes no
7 PHONE1 22-Nov-08 22-Nov-08 John yes no
17 PHONE1 01-Dec-08 01-Dec-08 Jan yes no
Any help greatly appreciated!
- References:
- Access query to return items free between two user input dates
- From: angel75
- Re: Access query to return items free between two user input dates
- From: John Spencer
- Access query to return items free between two user input dates
- Prev by Date: Re: Access query to return items free between two user input dates
- Next by Date: Sort Alphanumeric post codes
- Previous by thread: Re: Access query to return items free between two user input dates
- Next by thread: criteria 'between' explicit value 1 and Value 2 only.
- Index(es):
Relevant Pages
|