I have a tblWork that has a dozen fields in it.
It tracks hours worked for 2 employees at a time.
- fldDriverID
- fldDriverHours
- fldHelperID
- fldHelperHours
It also has a date field (fldDate) and a key to the ticket the work was performed on (fldTicketID).
So I assign the driver and the hours worked (1,15h) same for helper (1,13h)
What i want to do is do a payroll select that will get me the DriverHours and HelperHours for each employee. that is easy to do but the hard part is that the driver can be the helper and viseversa.
*
SampleData:
Expected Results
DateRange = 2007-2-1 -> 2007-2-3
Any Ideas?
What I tried, got close
[CODE=mysql]select
(select sum(fldDriverHo urs)
from tblWork
where tblWork.fldTick etID = t.fldTicketID and fldDriverID = ?EmployeeID) as DrivenHours,
(select sum(fldHelperHo urs)
from tblWork
where tblWork.fldTick etID = t.fldTicketID and fldHelperID = ?EmployeeID) as SwampHours
from tblWork w inner join tblTicket t on t.fldTicketID = w.fldTicketID
where t.fldDate >= '2007-10-10' and t.fldDate <= '2007-10-13'[/CODE]
It tracks hours worked for 2 employees at a time.
- fldDriverID
- fldDriverHours
- fldHelperID
- fldHelperHours
It also has a date field (fldDate) and a key to the ticket the work was performed on (fldTicketID).
So I assign the driver and the hours worked (1,15h) same for helper (1,13h)
What i want to do is do a payroll select that will get me the DriverHours and HelperHours for each employee. that is easy to do but the hard part is that the driver can be the helper and viseversa.
*
SampleData:
Code:
fldTicketID 1 2 3 4 5 fldDate 2007-2-1 2007-2-1 2007-2-1 2007-2-2 2007-2-3 fldDriverID 10 11 10 11 13 fldDriverHours 8 8 8 7.5 8 fldHelperID 11 10 13 13 10 fldHelperHours 8 7.5 8 8 8
DateRange = 2007-2-1 -> 2007-2-3
Code:
EmployeeID 10 11 13 DrivenHours 16 15.5 8 HelperHours 15.5 8 16
What I tried, got close
[CODE=mysql]select
(select sum(fldDriverHo urs)
from tblWork
where tblWork.fldTick etID = t.fldTicketID and fldDriverID = ?EmployeeID) as DrivenHours,
(select sum(fldHelperHo urs)
from tblWork
where tblWork.fldTick etID = t.fldTicketID and fldHelperID = ?EmployeeID) as SwampHours
from tblWork w inner join tblTicket t on t.fldTicketID = w.fldTicketID
where t.fldDate >= '2007-10-10' and t.fldDate <= '2007-10-13'[/CODE]
Comment