I have 2 tables. One that store charge-out rates for employees on project and the date from which the rate became effective. The other table holds timesheet information, recording the numbers of hours that an employee worked on different project on different dates.What I'm need to get is a list the hours per person per project per date with the appropriate charge-out rate.A simplified version of the data is:CREATE TABLE #Rates ( ProjectCode nvarchar(20) NOT NULL, EmployeeCode nvarchar(20) NOT NULL, EffectiveDate datetime NOT NULL, Rate money NOT NULL)CREATE TABLE #Hours ( ProjectCode nvarchar(20) NOT NULL, EmployeeCode nvarchar(20) NOT NULL, Date datetime NOT NULL, Hours tinyint)INSERT INTO #Rates (ProjectCode, EmployeeCode, EffectiveDate, Rate)SELECT 'Project1', 'Employee1', '2010-01-01', 100 UNION ALLSELECT 'Project1', 'Employee1', '2010-05-01', 115 UNION ALLSELECT 'Project1', 'Employee2', '2010-01-01', 80 UNION ALLSELECT 'Project2', 'Employee2', '2010-01-01', 90 UNION ALLSELECT 'Project2', 'Employee2', '2010-03-01', 100 UNION ALLSELECT 'Project2', 'Employee3', '2010-02-01', 50INSERT INTO #Hours (ProjectCode, EmployeeCode, Date, Hours)SELECT 'Project1', 'Employee1', '2010-04-20', 5 UNION ALLSELECT 'Project1', 'Employee1', '2010-04-21', 2 UNION ALLSELECT 'Project1', 'Employee1', '2010-05-05', 6 UNION ALLSELECT 'Project1', 'Employee2', '2010-04-25', 5 UNION ALLSELECT 'Project2', 'Employee2', '2010-01-13', 6 UNION ALLSELECT 'Project2', 'Employee2', '2010-04-01', 2 UNION ALLSELECT 'Project2', 'Employee3', '2010-03-01', 3 UNION ALLSELECT 'Project2', 'Employee3', '2010-04-01', 5I need to get out:ProjectCode EmployeeCode Date Hours Rate==================================================Project1 Employee1 2010-04-20 5 100Project1 Employee1 2010-04-21 2 100Project1 Employee1 2010-05-05 6 115Project1 Employee2 2010-04-25 5 80Project2 Employee2 2010-01-13 6 90Project2 Employee2 2010-04-01 2 100Project2 Employee3 2010-03-01 3 50Project2 Employee3 2010-04-01 5 50
I'm sure I've come across a solution to this before but can't seem to find it again (I think it involved using a calendar table) so any help would be greatly appreciated.Many thanksAlan