Here's something to get us started...--sample datadeclare @employee table (employeeid int, name varchar(10), team varchar(10))insert @employee select 1, 'x', 'team1'union all select 2, 'y', 'team2'union all select 5, 'z', 'team3'declare @projectest table (projectid int, employeeid int, hoursest int)insert @projectest select 1, 1, 6union all select 2, 5, 10declare @projectact table (projectid int, employeeid int, hoursact int)insert @projectact select 1, 1, 6union all select 1, 1, 10union all select 1, 2, 7declare @ProjTable table (projectid int, projectname varchar(10))insert @ProjTable select 1, 'proj1'union all select 2, 'proj2'--queryselect a.projectid, b.name as emplname, b.team, c.projectname, isnull(d.hoursest, 0) as hoursest, isnull(e.hoursact, 0) as hoursactfrom (select projectid, employeeid from @projectest union select projectid, employeeid from @projectact) a inner join @employee b on a.employeeid = b.employeeid inner join @ProjTable c on a.projectid = c.projectid left outer join (select projectid, employeeid, sum(hoursest) as hoursest from @projectest group by projectid, employeeid) d on a.employeeid = d.employeeid and a.projectid = d.projectid left outer join (select projectid, employeeid, sum(hoursact) as hoursact from @projectact group by projectid, employeeid) e on a.employeeid = e.employeeid and a.projectid = e.projectid
Ryan Randall Solutions are easy. Understanding the problem, now, that's the hard part.