I have a timesheet table and a department table with date ranges and want to attach the correct department to each timesheet entry.
Timesheet Department
---------------------- --------------------------------------
Name |Date |Hours Name |From |To |Dept
---------------------- --------------------------------------
Joe |6/1/2012 | 4 Joe |5/1/2012 |7/31/2012 |West
Joe |7/8/2012 | 2 Joe |8/1/2012 |1/1/2099 |East
Joe |8/4/2012 | 8
When querying the timesheet data I want the correct department for the day of the timesheet attached. The query should output this:
Joe |6/1/2012 | 4 |West
Joe |7/8/2012 | 2 |West
Joe |8/4/2012 | 8 |East
I have a hard time getting my head around how to join these different data sets to get to my goal. How can I select the correct Dept value for each timesheet entry if I don’t have the exact matching dates on which I can join but just a date range?
1 Answer