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:
01375339
Views:
32
Ok, is this better
;with cte_labor2 as 
(select TimeSheets.*, [HourlyRate] = (select top 1 HourlyRate from WorkerRates 
where WorkerRates.EmployeeID = 
TimeSheets.EmployeeID and TimeSheets.WorkDate >=WorkerRates.RateEffectiveDate and 
TimeSheets.WorkDate >=WorkerRates.RateAddedDate  
ORDER BY WorkerRates.RateEffectiveDate DESC) from TimeSheets)          

select EmployeeID, MONTH(WorkDate) as mWork, YEAR(WorkDate) as YDate, 
SUM(HoursWorked) as HoursWorked, 
SUM(HourlyRate*HoursWorked) as LaborAmount  
from cte_labor2 group by EmployeeID, YEAR(WorkDate), MONTH(WorkDate)
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