Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OK, another one
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01374859
Message ID:
01375534
Views:
33
>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...

I see, this seems now like a more obvious and direct approach, I wonder why I didn't think that straight? :)

Thanks.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform