I have 2 tables:
Manhours with fields: ManID, VehicleID, ManHours and RPTDate
Vehicles with fields: VehicleID and Vehicle
I am trying to create a query that sums the ManHours for each vehicle based on a given date range. The following query works:
SELECT Sum(manhours.Manhours) AS SumYearHours
FROM manhours
HAVING (((DatePart("yyyy",[rptdate]))=2002) AND ((DatePart("m",[rptdate])) Between 7 And 12) AND ((manhours.VehicleID)=8)) OR (((DatePart("yyyy",[rptdate]))=2003) AND ((DatePart("m",[rptdate])) Between 1 And 6) AND ((manhours.VehicleID)=8));
but it only gives me the hours for vehicleID 8.
I have tried to GROUP BY VehicleID (I then remove the expression from VehicleID) but I keep getting the message "You tried to execute a query that does not include the expression 'DatePart("yyyy",[rptdate]))=2002) AND ((DatePart("m",[rptdate])) Between 7 And 12) AND ((manhours.VehicleID)=8)) OR (((DatePart("yyyy",[rptdate]))=2003) AND ((DatePart("m",[rptdate])) Between 1 And 6' as part of an aggregate function.
What am I doing wrong, everything I read states that you can only use group by where you use aggregate functions.
Manhours with fields: ManID, VehicleID, ManHours and RPTDate
Vehicles with fields: VehicleID and Vehicle
I am trying to create a query that sums the ManHours for each vehicle based on a given date range. The following query works:
SELECT Sum(manhours.Manhours) AS SumYearHours
FROM manhours
HAVING (((DatePart("yyyy",[rptdate]))=2002) AND ((DatePart("m",[rptdate])) Between 7 And 12) AND ((manhours.VehicleID)=8)) OR (((DatePart("yyyy",[rptdate]))=2003) AND ((DatePart("m",[rptdate])) Between 1 And 6) AND ((manhours.VehicleID)=8));
but it only gives me the hours for vehicleID 8.
I have tried to GROUP BY VehicleID (I then remove the expression from VehicleID) but I keep getting the message "You tried to execute a query that does not include the expression 'DatePart("yyyy",[rptdate]))=2002) AND ((DatePart("m",[rptdate])) Between 7 And 12) AND ((manhours.VehicleID)=8)) OR (((DatePart("yyyy",[rptdate]))=2003) AND ((DatePart("m",[rptdate])) Between 1 And 6' as part of an aggregate function.
What am I doing wrong, everything I read states that you can only use group by where you use aggregate functions.