I modified the sql to deal with your Date criteria, and to allow for employeeIds in (602,603)
and WorkIds in (7,10,12)
The revised SQL is
Code:
SELECT [%$##@_Alias].EmployeeID
,[%$##@_Alias].WorkcodeID
,Sum([%$##@_Alias].SumOfBillableHours) AS SumOfSumOfBillableHours
FROM (SELECT TimeCard.EmployeeId
, Sum(tblTimeCardHours.BillableHours) AS SumOfBillableHours
, tblTimeCardHours.dateWorked
, tblTimeCardHours.workCodeId
FROM
tblTimeCardHours INNER JOIN TimeCard ON
tblTimeCardHours.TimeCardId = TimeCard.TimeCardid
GROUP BY
TimeCard.EmployeeId, tblTimeCardHours.dateWorked, tblTimeCardHours.workCodeId
HAVING
(((TimeCard.EmployeeId) IN (602,603)) AND
((tblTimeCardHours.workCodeId)In(7,10,12) AND
tblTimeCardHours.dateWorked>#31/12/2013# ))
) AS [%$##@_Alias]
GROUP BY [%$##@_Alias].EmployeeID
,[%$##@_Alias].WorkcodeID;
The result of this SQL/query is:
EmployeeID |
WorkcodeID |
SumOfSumOfBillableHours |
602 |
7 |
5 |
602 |
10 |
7 |
602 |
12 |
40 |
603 |
10 |
5 |
603 |
12 |
4 |
Because of the way the foum adds this graphics, I had to put the results before the test data!! It was trying to put my text entries into the table data grids??? So read the table/data changes first to get the right sequence of events.
I modified test data to have the following data:
Added employeeID 603
EmployeeId |
TimeCardid |
602 |
1 |
603 |
2 |
Added workcodeIds and hours for EmployeeID 602 and 603 to ensure here were records for
both employees and workcodeIds including 7, 10 and 12
TimeCardIhoursId |
BillableHours |
dateWorked |
workCodeId |
TimeCardId |
1 |
8 |
20/01/2014 |
12 |
1 |
2 |
8 |
02/03/2014 |
12 |
1 |
3 |
8 |
24/02/2014 |
12 |
1 |
4 |
8 |
05/09/2014 |
12 |
1 |
5 |
8 |
05/12/2014 |
12 |
1 |
6 |
7 |
05/12/2014 |
10 |
1 |
7 |
5 |
23/03/2014 |
7 |
1 |
8 |
4 |
24/03/2014 |
12 |
2 |
9 |
5 |
24/03/2014 |
10 |
2 |