Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Place Rollup at the bottom and group by total in the rollup

Status
Not open for further replies.

ladyemrys

Programmer
Aug 17, 2007
44
0
0
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top