Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OK, another one
Message
From
20/01/2009 12:16:48
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01374859
Message ID:
01375533
Views:
25
Here's the one I've used...
SELECT TimeSheets.EmployeeID, Month(WorkDate) as MonthPay , YEAR(WorkDate) AS YearPay,
   SUM(TimeSheets.HoursWorked * WorkerRates.HourlyRate)  AS LaborDollars
        FROM TimeSheets
              JOIN WorkerRates ON WorkerRates.EmployeeID = TimeSheets.EmployeeID 

                  WHERE WorkerRates.RateEffectiveDate = 
                        (SELECT MAX(RateEffectiveDate) FROM WorkerRates RatesTemp
                                      WHERE RateEffectiveDate <= WorkDate AND 
                                                     RateAddedDate <= WorkDate AND 
                                                   RatesTemp.EmployeeID = TimeSheets.EmployeeID)
    GROUP BY TimeSheets.EmployeeID, Month(WorkDate),YEAR(WorkDate)
Obviously, you could use a CTE as well.

Our execution plans are different....yours is interesting....obvoiusly, more than one way to do it.

Later tonight I'll try to post the execution plans.

Thanks for participating...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform