Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
OK, another one
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
01374859
Message ID:
01375339
Vues:
24
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform