I need to get an output that combines values from 2 tables based on StaffID and ProjectID. From the Timesheet table I need the total number of hours a staff spent on a project. From the Assignment table I need to show the estimated hours per staff. From the Staff table, I need to show the staff name.
While I can individually get the right results from the following 2 queries, I do not know how to combine them into 1 SQL Statement that joins all 3 tables while displaying the appropriate Aggregate value from TimeSht.
Declare @ProjID int
Select @ProjID=2003003
SELECT ITstaff.Staff_ID,ITstaff.FName,ITstaff.Lname,AS tHours
FROM ITstaff
LEFT JOIN ITstaff ON TimeSht.StaffID=ITstaff.Staff_ID
WHERE TimeSht.ProjID=@ProjID
SELECT Sum(TimeSht.NumberOfHours)
FROM TimeSht
WHERE TimeSht.ProjID=@ProjID
GROUP BY TimeSht.StaffID
Any Ideas?
While I can individually get the right results from the following 2 queries, I do not know how to combine them into 1 SQL Statement that joins all 3 tables while displaying the appropriate Aggregate value from TimeSht.
Declare @ProjID int
Select @ProjID=2003003
SELECT ITstaff.Staff_ID,ITstaff.FName,ITstaff.Lname,AS tHours
FROM ITstaff
LEFT JOIN ITstaff ON TimeSht.StaffID=ITstaff.Staff_ID
WHERE TimeSht.ProjID=@ProjID
SELECT Sum(TimeSht.NumberOfHours)
FROM TimeSht
WHERE TimeSht.ProjID=@ProjID
GROUP BY TimeSht.StaffID
Any Ideas?