I have a payroll data sql table that shows the wage rates and effective dates associated with these wage rates, as well as hours of work on different dates. It looks something like this:
EMPID DateWorked Hours WageRate EffectiveDate
1 1/1/2010 10 7.00 6/1/2009
1 1/1/2010 10 7.25 6/10/2009
1 1/1/2010 10 8.00 2/1/2010
1 1/10/2010 ...
2 1/1/2010 ...
...
Etc. In principle, the data were combined in such a way that for each working day the entire history of the employee’s wages is combined together, and I want to get the wage rate associated with the last effective date, which is no later than the work date. So in the above example, the 7.25 rate, which will take effect on 6/10/2009, is what I want.
What request can I put together for this? I can use MAX (EffectiveDate) along with criteria based on being up to the date of work, but this gives me the latest date, I want a related wage. For this I use Sql Server.
Alternatively, I have source tables that were used to create this data. One of them contains work dates, as well as hours, as well as EMPID, and the other contains a list of wage rates and effective dates. Is there a way to join them instead, which would correctly apply the correct wage rate for each working day?
, EMPID, DateWorked - . , , .