SELECT tblEmployee.employeeLastName + ', ' + tblEmployee.employeeFirstName AS empFullName, SUM(DATEDIFF('h', Format(tblProduction.startDate,
'short date') + ' ' + tblStartTime.[time], Format(tblProduction.endDate, 'short date') + ' ' + tblEndTime.[time])) AS totalHours, tblProducts.sam,
tblProduction.totalProduced, tblTeams.teamName, tblTeams.teams_ID,
(SELECT COUNT(tblTeamMembers.employee_ID) AS teamCount
FROM tblTeamMembers
WHERE tblTeamMembers.teams_Id = tblTeams.teams_ID)
FROM (tblEmployee RIGHT OUTER JOIN
(((((tblTeamMembers INNER JOIN
tblTeams ON tblTeamMembers.teams_Id = tblTeams.teams_ID) INNER JOIN
tblProduction ON tblTeams.teams_ID = tblProduction.teams_ID) INNER JOIN
tblProducts ON tblProduction.product_ID = tblProducts.product_ID) INNER JOIN
tblTime tblStartTime ON tblProduction.startTime = tblStartTime.time_ID) INNER JOIN
tblTime tblEndTime ON tblProduction.endTime = tblEndTime.time_ID) ON tblEmployee.employee_ID = tblTeamMembers.employee_ID)
GROUP BY tblEmployee.employeeLastName + ', ' + tblEmployee.employeeFirstName, tblProducts.sam, tblProduction.totalProduced, tblTeams.teamName,
tblTeams.teams_ID
ORDER BY tblEmployee.employeeLastName + ', ' + tblEmployee.employeeFirstName
|