473,417 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

Find records within a date range

Hi all

I am having a head bursting nightmare trying to get a query to work, I will try and explain.

I have developed a database for the calculating storage costs in a warehouse. Customers are charged a daily rate while their pallets are stored in the depot warehouse. I have fields in a table called DateIn and dateOut both are short dates. I have forms to book pallets in and book them out and I can see all is fine up to this point.

I want to make a report called INVOICE based on a query. I have a form you open and select the date range for the invoice and enter then in to text boxes called txtStartDate and txtEndDate. I know how to pass these values to the query that has DateIn and DateOut in it

What I need to find is any pallets that were in the warehouse during the invoice period or any part of the invoice period.

If any one can offer advice or point me in the right direction I would be very grateful.

thanks
Tony
Dec 2 '08 #1
3 2234
gpl
152 100+
@tonymcc
The simplest way of testing for a period overlap of dates is to do the following :
Assume :
DateIn and DateOut are the dates the the pallet were in the warehouse
InvoiceSt and InvoiceEnd are the invoicing periods

Your where clause will look a bit like this (ignoring the time factor)

Expand|Select|Wrap|Line Numbers
  1. Where DateIn <= InvoiceEnd And DateOut >= InvoiceSt
In other words, it arrived in the warehouse before the invoice period ended and left after the invoice period started - if you hold NULL for the DateOut when you dont know when it will ship, dummy in the InvoiceEnd for the DateOut :

Expand|Select|Wrap|Line Numbers
  1. Where DateIn <= InvoiceEnd And IIF(DateOut IS NULL, InvoiceEnd, DateOut) >= InvoiceSt
Hope this helps
Graham
Dec 2 '08 #2
Thanks Graham you hit the nail on the head.
I sat and worked out all the permutations and then tried to build a query for this and it had about 7 OR's and 8 AND's which ended up being longer than my arm.
You came along and did it in a one liner!! I obviously could not see the forest for all the trees.
Thanks again Graham

Tony
Dec 2 '08 #3
gpl
152 100+
Tony
I had to do this for work a couple of months ago, the original code was miles long, I couldnt work out why it was so complex.

Glad to have helped
Graham
Dec 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dbarchitech | last post by:
hi, i'm building a query to find narrow ranges of zip codes within broader ranges in a table (for tax purposes). for example: LOW_ZIP HI_ZIP 23400 23499 need to find 23401 ...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
3
by: Gary | last post by:
Sorry to waste everyone's time with a query which is so simple, but as a new user of Access I have created a client database and one of the fields is "next contact due" as the name implies, this is...
1
by: Manton | last post by:
Access 2000. I have a field in a table (tbl_data entry) which has a field called Free and another field called SD (containing 2 options: 5 and 6) The Free field is a yes/no format. I'd like to...
18
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
1
by: RussCRM | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
8
by: mvdave | last post by:
Hello all & I hope I'm posting in the right place.. I need to load a temporary table with a range of sequential dates, passing it a beginning and an end date from a criteria form. I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.