I have a query that is producing a report of Full Time employees and i still need to group them by those having over 80 hours and under 80 hours (which is the rollup total), and the rollup seems to be positioned at the beginning of each employee's records, I'd like it to be at the end. If you have any ideas on how to make it more efficient as well, I'm all ears! thanks in advance!!!
Here's the query so far:
SELECT E.BadgeNum, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName AS Name,
TKP.PayrollCode as PayrollCode, SUM(TKP.PayTime/3600) as 'Pay Hours'
FROM TKPAY TKP inner join Employees E
ON TKP.EmployeeId = E.EmployeeId
where exists (select 1 from EmployeeStatus S where S.EmployeeID = E.EmployeeID and S.EmployeeTypeID = '1')
GROUP BY E.BadgeNum, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName, TKP.PayrollCode WITH ROLLUP
UNION
SELECT E.BadgeNum, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName AS Name,
TKPS.PayrollCode as PayrollCode, SUM(TKPS.PayTime/3600) as 'Pay Hours'
FROM TkPaySupplementary TKPS
inner join Employees E
ON TKPS.EmployeeId = E.EmployeeId
where exists (select 1 from EmployeeStatus S where S.EmployeeID = E.EmployeeID and S.EmployeeTypeID = '1')
GROUP BY E.BadgeNum, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName, TKPS.PayrollCode WITH ROLLUP
ORDER BY 2, 1, 3
Here's the query so far:
SELECT E.BadgeNum, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName AS Name,
TKP.PayrollCode as PayrollCode, SUM(TKP.PayTime/3600) as 'Pay Hours'
FROM TKPAY TKP inner join Employees E
ON TKP.EmployeeId = E.EmployeeId
where exists (select 1 from EmployeeStatus S where S.EmployeeID = E.EmployeeID and S.EmployeeTypeID = '1')
GROUP BY E.BadgeNum, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName, TKP.PayrollCode WITH ROLLUP
UNION
SELECT E.BadgeNum, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName AS Name,
TKPS.PayrollCode as PayrollCode, SUM(TKPS.PayTime/3600) as 'Pay Hours'
FROM TkPaySupplementary TKPS
inner join Employees E
ON TKPS.EmployeeId = E.EmployeeId
where exists (select 1 from EmployeeStatus S where S.EmployeeID = E.EmployeeID and S.EmployeeTypeID = '1')
GROUP BY E.BadgeNum, E.LastName + ', ' + E.FirstName + ' ' + E.MiddleName, TKPS.PayrollCode WITH ROLLUP
ORDER BY 2, 1, 3