I am trying to modify an existing query to show when a person has 0 hours worked. I need all the records listed in the Exc Table and only the HoursWorked Field from the Records Table when there is a matching record in the Exc Table, if there is not a record that matches the record in the Exc Table then I still want to return the Exc Table record with an HoursWorked of 0.00. The existing query will not show a record that is in the Exc Table if it is not also in the Records Table. I have been working on this for days with no luck, please help. Here is the query...
SELECT Exc.ExceptionOK, Exc.Comment, Exc.Manager, Exc.CreateDate, Exc.MaintDate, Records.HoursWorked, Exc.Employee, Exc.ExceptionDate
FROM (SELECT employee_account_name AS Employee, CONVERT(varchar(10), start_date_time, 101) AS TimeDate, CONVERT(Decimal(9, 2),
SUM(TimePeriod)) AS HoursWorked
FROM (SELECT EmpMaster.employee_account_name, dbo.Time_Record.start_date_time, DATEDIFF(minute, dbo.Time_Record.start_date_time,
dbo.Time_Record.end_date_time) / 60.0 AS TimePeriod
FROM dbo.Time_Record RIGHT OUTER JOIN
dbo.Employee_Master AS EmpMaster ON
dbo.Time_Record.employee_account_name = EmpMaster.employee_account_name
WHERE (EmpMaster.supervisor <> 'Y') AND (EmpMaster.employee_account_name = @empAccount)) AS TimeRecords
GROUP BY employee_account_name, CONVERT(varchar(10), start_date_time, 101)) AS Records RIGHT OUTER JOIN
dbo.TimeExceptions AS Exc ON Records.Employee = Exc.Employee AND Records.TimeDate = Exc.ExceptionDate
WHERE (Records.HoursWorked > @overtime) OR
(Records.HoursWorked < @undertime)
ORDER BY Records.Employee, Records.TimeDate
SELECT Exc.ExceptionOK, Exc.Comment, Exc.Manager, Exc.CreateDate, Exc.MaintDate, Records.HoursWorked, Exc.Employee, Exc.ExceptionDate
FROM (SELECT employee_account_name AS Employee, CONVERT(varchar(10), start_date_time, 101) AS TimeDate, CONVERT(Decimal(9, 2),
SUM(TimePeriod)) AS HoursWorked
FROM (SELECT EmpMaster.employee_account_name, dbo.Time_Record.start_date_time, DATEDIFF(minute, dbo.Time_Record.start_date_time,
dbo.Time_Record.end_date_time) / 60.0 AS TimePeriod
FROM dbo.Time_Record RIGHT OUTER JOIN
dbo.Employee_Master AS EmpMaster ON
dbo.Time_Record.employee_account_name = EmpMaster.employee_account_name
WHERE (EmpMaster.supervisor <> 'Y') AND (EmpMaster.employee_account_name = @empAccount)) AS TimeRecords
GROUP BY employee_account_name, CONVERT(varchar(10), start_date_time, 101)) AS Records RIGHT OUTER JOIN
dbo.TimeExceptions AS Exc ON Records.Employee = Exc.Employee AND Records.TimeDate = Exc.ExceptionDate
WHERE (Records.HoursWorked > @overtime) OR
(Records.HoursWorked < @undertime)
ORDER BY Records.Employee, Records.TimeDate