December 8, 2011 at 12:06 am
Hi i have below query.
SELECT *
FROM(
SELECT
YEAR(calldate) [Year],
--COUNT(REQUESTS.reqid),
CASE MONTH(calldate)
-- WHEN 1 THEN 'January'
-- WHEN 2 THEN 'February'
-- WHEN 3 THEN 'March'
WHEN 4 THEN 'April'
WHEN 5 THEN 'May'
WHEN 6 THEN 'June'
WHEN 7 THEN 'July'
WHEN 8 THEN 'August'
WHEN 9 THEN 'September'
WHEN 10 THEN 'October'
WHEN 11 THEN 'November'
--WHEN 12 THEN 'December'
END as [Month],
--customerid,
-- SCHEDULE_EMPLOYEE.EMPID 'EMPID',
EMPLOYEE.EMPLOYEENAME 'EMPLOYEENAME',
REQUESTS.reqid
FROM requests
INNER JOIN SCHEDULE_EMPLOYEE ON SCHEDULE_EMPLOYEE.REQID = REQUESTS.REQID
INNER JOIN EMPLOYEE ON SCHEDULE_EMPLOYEE.EMPID = EMPLOYEE.EMPID
where YEAR(calldate) = 2011
) yearwise
--WorkOrders
PIVOT
(
count(reqid)
FOR [Month] IN (
--[January],[February],[March],
[April],
[May],[June],[July],[August],
[September],[October],[November]
-- ,[December]
)
) AS PivotTable
ORDER BY [Year], EMPLOYEENAME
how to add row total and column total in this query.
December 8, 2011 at 9:01 am
Could you please provide us with some sample data so we can more easily assist you with your query?
EDIT: Also if you uncomment the --COUNT(REQUESTS.reqid), won't that give you your row total?
Also you're probably going to get told by a lot of people that the row total and column totals are values that should be handled outside of T-SQL as these are presentation layer issues.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply