gbnorton
asked on
query to sum fields over a date range.
I need a query that will sum the netwtadded and netwtremoved fields over a data range. The query will be used for a report.
Use the equipment number 2-40-21-001.
Start date: 8/6/2014
End date: 8/14/2014
The query I’ve been using is: qry_rptEqDateRange
Note that I’m querying on the End date – 1.
I've attached the database.
Thanks,
Brooks
Chemical.zip
Use the equipment number 2-40-21-001.
Start date: 8/6/2014
End date: 8/14/2014
The query I’ve been using is: qry_rptEqDateRange
Note that I’m querying on the End date – 1.
I've attached the database.
Thanks,
Brooks
Chemical.zip
ASKER
I want to exclude the last entry from the results.
if your date range is 8/1/2014 and 8/28/2014,
your criteria will be
between 8/1/2014 and 8/27/2014
you will exclude all records with date of 8/28/2014
be more specific about your criteria
.
your criteria will be
between 8/1/2014 and 8/27/2014
you will exclude all records with date of 8/28/2014
be more specific about your criteria
.
SomeDT Between startDT and EndDT INCLUDES dates at both ends. So it is the same as
SomeDT >= StartDT and SomeDT <= EndDT
If you want to exclude the EndDT, then use
SomeDT >= StartDT and SomeDT < EndDT
OR
SomeDT Between startDT and EndDT - 1
I didn't look at your attachment. I can't download them here. Your problem could be that your date includes time and that changes your criteria. You can use the DateValue() function to pull out only the date part of a date/time field.
DateValue(SomeDT) Between startDT and EndDT
SomeDT >= StartDT and SomeDT <= EndDT
If you want to exclude the EndDT, then use
SomeDT >= StartDT and SomeDT < EndDT
OR
SomeDT Between startDT and EndDT - 1
I didn't look at your attachment. I can't download them here. Your problem could be that your date includes time and that changes your criteria. You can use the DateValue() function to pull out only the date part of a date/time field.
DateValue(SomeDT) Between startDT and EndDT
ASKER
Pat, I'll use the < as you described. Simpler. The date range works fine. It is the summing of the netwtadded and netwtremoved fields that I need. Sum the netwtadded field for the records between start date and end date. Thanks,]
Brooks
Brooks
ok., i'll leave the two of you..
you seems to be not interested to respond in my comment.
you seems to be not interested to respond in my comment.
ASKER
I apologize Rey. That was not intended. In my mind, the date range is not my problem. It is the summing of the netwtadded and netwtremoved fields.
The criteria should be all records from start date to < end date.
The criteria should be all records from start date to < end date.
Rey, FYI - Between included dates at both ends of the range.
<Rey, FYI - Between included dates at both ends of the range. >
I know that long time ago.
I know that long time ago.
I thought so but your previous answer indicated that Between excludes the end date. If I misunderstood it, I apologize.
ASKER
In the database I uploaded, the table is Data. Using the criteria:
Equipment: 2-40-21-001
Date Range: 8/6/2014 to 8/14/2014
The selected records are:
Date Used Operator Net Wt Added Net Wt Removed Notes
8/6/2104 0326 15 0
8/10/2014 0326 25 0
I need the query to sum the Net Wt Added records. And sum the Net Wt Removed records. In the end I'll subtract the removed from the added and divide by the number of days.
Current query:
SELECT data.DateUsed, data.Operator, data.EquipmentNumber, data.EquipmentDescription, data.ChemicalName, data.NetAddedWT, data.NetRemovedWT, data.Notes
FROM data
WHERE ((data.[DateUsed]) >= [Forms]![Switchboard]![cbo StartDate] ) And ((data.[DateUsed]) < [Forms]![Switchboard]![cbo EndDate]) AND ((data.[EquipmentNumber])= '2-40-21-0 01')
ORDER BY data.[DateUsed];
I hope this helps.
Thanks,
Brooks
Equipment: 2-40-21-001
Date Range: 8/6/2014 to 8/14/2014
The selected records are:
Date Used Operator Net Wt Added Net Wt Removed Notes
8/6/2104 0326 15 0
8/10/2014 0326 25 0
I need the query to sum the Net Wt Added records. And sum the Net Wt Removed records. In the end I'll subtract the removed from the added and divide by the number of days.
Current query:
SELECT data.DateUsed, data.Operator, data.EquipmentNumber, data.EquipmentDescription,
FROM data
WHERE ((data.[DateUsed]) >= [Forms]![Switchboard]![cbo
ORDER BY data.[DateUsed];
I hope this helps.
Thanks,
Brooks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! Thank you!
Brooks
Brooks
ASKER
Perfect! Thank you!
Brooks
Brooks
You are welcome!
/gustav
/gustav
why?
shouldn't it be End date + 1