I am fairly new to writing in SQL and I have a union query that I can't seem to get right. I know it is possible but I can't seem to make it work for me. I need to add together the TotalDays by EmpName. I also need to keep the week ending in there. I would really appreciate it if anyone could tell me how to do this? Thank you!
SELECT
IIf([EmployeeComm]=1111,"Name1",IIf([EmployeeComm]=2222,"Name2",IIf([EmployeeComm]=2553,"Name3",IIf([EmployeeComm]=2923,"Name4",IIf([EmployeeComm]=3333,"Name5",IIf([EmployeeComm]=4444,"Name6",IIf([EmployeeComm]=4807,"Name7",IIf([EmployeeComm]=9999,"Name8","Null")))))))) AS EmpName, HoursWorked.WeekEnding, HoursWorked.NoDaysWorked AS TotalDays
FROM Employees INNER JOIN (HospitalBillingLevels INNER JOIN (PhysicianAgreements INNER JOIN (HoursWorked INNER JOIN InsuranceChargeperInvoice ON HoursWorked.InvNo = InsuranceChargeperInvoice.InvNo) ON PhysicianAgreements.PhysDealNo = HoursWorked.PhysAgreement) ON HospitalBillingLevels.HospitalAgreement = HoursWorked.HospAgreement) ON Employees.EmpID = HospitalBillingLevels.EmployeeCommis
WHERE (((HoursWorked.WeekEnding)=#7/13/2013#))
UNION ALL
SELECT IIf([EmployeeCommis]=1111,"Name1",IIf([EmployeeCommis]=2222,"Name2",IIf([EmployeeCommis]=2553,"Name3",IIf([EmployeeCommis]=2923,"Name4",IIf([EmployeeCommis]=3333,"Name5",IIf([EmployeeCommis]=4444,"Name6",IIf([EmployeeCommis]=4807,"Name7",IIf([EmployeeCommis]=9999,"Name8","Null")))))))) AS EmpName, HoursWorked.WeekEnding, HoursWorked.NoDaysWorked AS TotalDays
FROM Employees INNER JOIN (HospitalBillingLevels INNER JOIN (PhysicianAgreements INNER JOIN (HoursWorked INNER JOIN InsuranceChargeperInvoice ON HoursWorked.InvNo = InsuranceChargeperInvoice.InvNo) ON PhysicianAgreements.PhysDealNo = HoursWorked.PhysAgreement) ON HospitalBillingLevels.HospitalAgreement = HoursWorked.HospAgreement) ON Employees.EmpID = HospitalBillingLevels.EmployeeCommis
WHERE (((HoursWorked.WeekEnding)=#7/13/2013#));