I am developing a report that calculates cost based on, Hours Worked * the effective Rate for the date the work was completed. The Hours Worked information resides in one table and the Rate information in another. I have written code to make this work using VBA, but was wondering if this could be done with one or more queries.
The tables are structure as follows:
For RsrcID 1, I would like to return the first rate with an EffDate that is <= WorkDate
For RsrcID 2, there was error when entering the EffDate as you will notice the EffDate is greater than the WorkDate so I need to retrieve the first rate that is > the WorkDate
For RsrcID 3, there was no rate information entered. In the event of null value I would like a default rate of 30 entered, which I would handle like this NZ(Rate, 30)
I would like to write a query that would join these tables shown above with the following results:
Thanks in advance.
The tables are structure as follows:
Code:
[B]Hours Worked[/B]
RsrcID Hours WorkDate
1 1 12/31/2007
1 1 1/1/2008
1 1 3/1/2008
2 1 5/1/2008
3 1 3/1/2008
[B]Rate[/B]
RsrcID Rate EffDate
1 10 1/1/2007
1 15 1/1/2008
1 20 5/1/2008
2 25 6/1/2008
2 30 8/1/2008
3
For RsrcID 1, I would like to return the first rate with an EffDate that is <= WorkDate
For RsrcID 2, there was error when entering the EffDate as you will notice the EffDate is greater than the WorkDate so I need to retrieve the first rate that is > the WorkDate
For RsrcID 3, there was no rate information entered. In the event of null value I would like a default rate of 30 entered, which I would handle like this NZ(Rate, 30)
I would like to write a query that would join these tables shown above with the following results:
Code:
[B]Results[/B]
RsrcID Hours Rate WorkDate
1 1 10 12/31/2007
1 1 15 1/1/2008
1 1 20 3/1/2008
2 1 25 5/1/2008
3 1 30 3/1/2008
Thanks in advance.
Last edited: