I am have a problem with the ROLLUP operator. The table that I am querying is as such:
EMPLOYID EmplName Dept WCCode Gross SS MED FUTA SUTA
11000217 FLEURIMOND, ROSE 100002 NY8394 369.26 369.26 369.26 369.26 369.26
11000253 LAMBERT, JOY 100002 NY8394 299.12 299.12 299.12 299.12 299.12
11001076 DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
11000807 FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
11000966 JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
I am trying to total by Dept. My query is:
SELECT ISNULL(#tempTable.Employid, '') AS 'Employee ID', ISNULL(#tempTable.EmplName, '') AS Employee,
ISNULL(#tempTable.Dept, '') AS Department, ISNULL(#tempTable.WCCode, '') AS 'WC Code',
SUM(#tempTable.Gross) AS Gross, SUM(#tempTable.SS) AS 'FICA SS', SUM(#tempTable.Med) AS 'FICA Med',
SUM(#tempTable.FUTA) AS FUTA, SUM(#tempTable.SUTA) AS SUTA
from #tempTable
GROUP BY #tempTable.Dept, #tempTable.WCCode, #tempTable.EmplName, #tempTable.Employid WITH Rollup
#tempTable.EmplName
UNION ALL
SELECT ' ', ' ', ' ', 'Total: ', SUM(#tempTable.Gross), SUM(#tempTable.SS), SUM(#tempTable.Med), SUM(#tempTable.FUTA), SUM(#tempTable.SUTA)
FROM #tempTable
The output that I am getting is:
11000217 FLEURIMOND, ROSE 100002 NY8394 369.26 369.26 369.26 369.26 369.26
FLEURIMOND, ROSE 100002 NY8394 369.26 369.26 369.26 369.26 369.26
11000253 LAMBERT, JOY 100002 NY8394 299.12 299.12 299.12 299.12 299.12
LAMBERT, JOY 100002 NY8394 299.12 299.12 299.12 299.12 299.12
100002 NY8394 668.38 668.38 668.38 668.38 668.38
100002 668.38 668.38 668.38 668.38 668.38
11001076 DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
100003 NY8394 149.56 149.56 149.56 149.56 149.56
100003 149.56 149.56 149.56 149.56 149.56
11000807 FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
11000966 JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
100009 NY8394 1012.24 1012.24 1012.24 1012.24 1012.24
100009 1012.24 1012.24 1012.24 1012.24 1012.24
1830.18 1830.18 1830.18 1830.18 1830.18
Total: 1830.18 1830.18 1830.18 1830.18 1830.18
The totals are correct, but, as can be seen, I'm getting a 2nd line for each employee.
The output I'm looking for is:
11000217 FLEURIMOND, ROSE 100002 NY8394 369.26 369.26 369.26 369.26 369.26
11000253 LAMBERT, JOY 100002 NY8394 299.12 299.12 299.12 299.12 299.12
100002 668.38 668.38 668.38 668.38 668.38
11001076 DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
100003 149.56 149.56 149.56 149.56 149.56
11000807 FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
11000966 JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
100009 1012.24 1012.24 1012.24 1012.24 1012.24
Total: 1830.18 1830.18 1830.18 1830.18 1830.18
Can anyone help me with the Select statement? Thank you.
EMPLOYID EmplName Dept WCCode Gross SS MED FUTA SUTA
11000217 FLEURIMOND, ROSE 100002 NY8394 369.26 369.26 369.26 369.26 369.26
11000253 LAMBERT, JOY 100002 NY8394 299.12 299.12 299.12 299.12 299.12
11001076 DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
11000807 FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
11000966 JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
I am trying to total by Dept. My query is:
SELECT ISNULL(#tempTable.Employid, '') AS 'Employee ID', ISNULL(#tempTable.EmplName, '') AS Employee,
ISNULL(#tempTable.Dept, '') AS Department, ISNULL(#tempTable.WCCode, '') AS 'WC Code',
SUM(#tempTable.Gross) AS Gross, SUM(#tempTable.SS) AS 'FICA SS', SUM(#tempTable.Med) AS 'FICA Med',
SUM(#tempTable.FUTA) AS FUTA, SUM(#tempTable.SUTA) AS SUTA
from #tempTable
GROUP BY #tempTable.Dept, #tempTable.WCCode, #tempTable.EmplName, #tempTable.Employid WITH Rollup
#tempTable.EmplName
UNION ALL
SELECT ' ', ' ', ' ', 'Total: ', SUM(#tempTable.Gross), SUM(#tempTable.SS), SUM(#tempTable.Med), SUM(#tempTable.FUTA), SUM(#tempTable.SUTA)
FROM #tempTable
The output that I am getting is:
11000217 FLEURIMOND, ROSE 100002 NY8394 369.26 369.26 369.26 369.26 369.26
FLEURIMOND, ROSE 100002 NY8394 369.26 369.26 369.26 369.26 369.26
11000253 LAMBERT, JOY 100002 NY8394 299.12 299.12 299.12 299.12 299.12
LAMBERT, JOY 100002 NY8394 299.12 299.12 299.12 299.12 299.12
100002 NY8394 668.38 668.38 668.38 668.38 668.38
100002 668.38 668.38 668.38 668.38 668.38
11001076 DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
100003 NY8394 149.56 149.56 149.56 149.56 149.56
100003 149.56 149.56 149.56 149.56 149.56
11000807 FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
11000966 JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
100009 NY8394 1012.24 1012.24 1012.24 1012.24 1012.24
100009 1012.24 1012.24 1012.24 1012.24 1012.24
1830.18 1830.18 1830.18 1830.18 1830.18
Total: 1830.18 1830.18 1830.18 1830.18 1830.18
The totals are correct, but, as can be seen, I'm getting a 2nd line for each employee.
The output I'm looking for is:
11000217 FLEURIMOND, ROSE 100002 NY8394 369.26 369.26 369.26 369.26 369.26
11000253 LAMBERT, JOY 100002 NY8394 299.12 299.12 299.12 299.12 299.12
100002 668.38 668.38 668.38 668.38 668.38
11001076 DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
DILEONE, ROBERT 100003 NY8394 149.56 149.56 149.56 149.56 149.56
100003 149.56 149.56 149.56 149.56 149.56
11000807 FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
FERRERA, ROB 100009 NY8394 506.12 506.12 506.12 506.12 506.12
11000966 JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
JONES, CATHY 100009 NY8394 506.12 506.12 506.12 506.12 506.12
100009 1012.24 1012.24 1012.24 1012.24 1012.24
Total: 1830.18 1830.18 1830.18 1830.18 1830.18
Can anyone help me with the Select statement? Thank you.