I have an employee table with changes in positions, Org, labor categories, pay, etc. (This is a simplistic view of what I'm doing, but I get the idea across.)
[Employee]
EmplId EffectDate OrgId Position PayRate
1234 1/1/2006 1.1.1 Laborer 10.00
1234 4/1/2006 1.2.4 Tech 12.00
1234 6/1/2006 1.5.2 Manager 15.00
I have a second table with timesheet entries
[Timesheet]
EmplId WorkDate Hours
1234 1/1/2006 8
1234 1/2/2006 8
1234 1/3/2006 8
....
1234 5/1/2006 8
....
1234 6/2/2006 8
I need to join the activity from the Timesheet table with the Employee data for a report but I want to show the Employee's OrgId, Position, PayRate he would have been at on that timesheet date. In other words, all timesheet activity after 4/1/2006 and prior to 6/1/2006 would be 'charged' to the position he came into on 4/1/2006 and all activity after 6/1/2006 would be 'charged' to the position he came into 6/1/2006.
Along the lines of what I've tried but DOESN'T work is:
SELECT EmplId, OrgId, Position, PayRate, WorkDate, Hours FROM Employee
JOIN Timesheet ON Employee.EmplId = Timesheet.EmplId
WHERE WorkDate >= EffectDate AND WorkDate < EffectDate
Any help would be appreciated!
[Employee]
EmplId EffectDate OrgId Position PayRate
1234 1/1/2006 1.1.1 Laborer 10.00
1234 4/1/2006 1.2.4 Tech 12.00
1234 6/1/2006 1.5.2 Manager 15.00
I have a second table with timesheet entries
[Timesheet]
EmplId WorkDate Hours
1234 1/1/2006 8
1234 1/2/2006 8
1234 1/3/2006 8
....
1234 5/1/2006 8
....
1234 6/2/2006 8
I need to join the activity from the Timesheet table with the Employee data for a report but I want to show the Employee's OrgId, Position, PayRate he would have been at on that timesheet date. In other words, all timesheet activity after 4/1/2006 and prior to 6/1/2006 would be 'charged' to the position he came into on 4/1/2006 and all activity after 6/1/2006 would be 'charged' to the position he came into 6/1/2006.
Along the lines of what I've tried but DOESN'T work is:
SELECT EmplId, OrgId, Position, PayRate, WorkDate, Hours FROM Employee
JOIN Timesheet ON Employee.EmplId = Timesheet.EmplId
WHERE WorkDate >= EffectDate AND WorkDate < EffectDate
Any help would be appreciated!