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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate sum of values in fields by date

Status
Not open for further replies.

PavelowFE

Technical User
Jan 13, 2009
39
0
0
US
Hi again.

Trying to get a query to sum the values in all the records of one field, but only between certain dates. I've manage to do the Expression to sum the values, but can't figure out how to do it for a date range.

Thanks in advance for the help again.

Vince
 
Simply use a WHERE clause with the BETWEEN operator in your SQL code.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Can you provide me an example of what it looks like?

Here's what I have so far.

SELECT Sum([# of Operators Trained]) AS Expr1
FROM [Mission Report];

Thanks,

Vince

 
an example of what it looks like
SELECT Sum([# of Operators Trained]) AS Expr1
FROM [Mission Report]
WHERE [your date field] Between #2009-01-01# And #2009-06-30#

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Code:
SELECT Sum([# of Operators Trained]) AS Expr1
FROM [Mission Report]
WHERE YourDateField BETWEEN #StartDate# and #EndDate#

Randy
 
Finally got it to work. However, I tried to create a second one. It seemed to work at first, however the sum is not correct according to the table. It should have summed up to 20, but it comes out as 12. The difference between the two is that the "# of Aircrew Trained" field in Mission Report is a lookup to another table with the value set according to the airframe the user selects.

SELECT Sum([# of Operators Trained]) AS Expr1, Sum([# of Aircrew Trained]) AS Expr2
FROM [Mission Report]
WHERE [Date Tng Completed] Between #10/1/2008# And #9/30/2009#;

The help is greatly appreciated!

Vince
 
Are you sure you want a Sum instead of a Count ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes, I don't want to count how many records I have, I want the total of the values input into each record.

I.e. (The # of Aircrew Trained is a ComboBox to a table that has all the airframes and how many aircrew are in each. The user selects the airframe, but the value is the number assigned to the airframe selected).

Date # of Aircrew Trained # of Operators Trained
14 Jul 09 3 5
15 Jul 09 5 12

Total Aircrew Trained 8
Total Operators Trained 17

Thanks,

Vince
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top