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

Click here to load this message in the networking platform