Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How can I put Total as a row rather than column?

Author  Topic 

simflex
Constraint Violating Yak Guru

327 Posts

Posted - 2010-03-25 : 01:30:58
ReportName ReportTItle ReportTotal YTD

TeamSite My Team 1 3
NewSite Other Team 4 4


Now, here is where the trick comes in.

I want to calculate the total of Report Total and place it as row as shown below:

ReportName ReportTItle ReportTotal YTD

TeamSite My Team 1 3
NewSite Other Team 4 4

Total 5 7

However, my calculation is not right because the Total is being placed as a column instead of Row.

Can you help please?

More concerned about this:

SUM(CASE rq.reportQTitle
WHEN rq.reportTitle in ('Homicide','Rape','Robbery') THEN responseTotal
END) as Total


Please see my code and thanks as always.
sorry I can't get columns and value to align correctly.


Select rq.ReportName, rq.reportTitle,
(CASE isComments
WHEN 0 THEN STR(ResponseTotal)
ELSE ResponseComments
END)as ReponseTotal,Sum(responseTotal) as YTD,
SUM(CASE rq.reportQTitle
WHEN rq.reportTitle in ('Homicide','Rape','Robbery') THEN responseTotal
END) as Total

FROM ReportsData rd, ReportQuestions rq,ReportDataGroup rg
WHERE rq.ReportQID = rd.ReportQID
AND rd.ReportGroupID=rg.ReportGroupID
AND rg.StartDate = '11/1/2009'
AND rg.EndDate = '11/5/2009'
GROUP BY rq.ReportName,reportTitle, responseTotal, ReportQOrder,isComments,responseComments
ORDER BY reportQOrder

stepson
Aged Yak Warrior

545 Posts

Posted - 2010-03-25 : 02:29:16
use union all

(your select ...)

UNION ALL
(select ... for totals)
Go to Top of Page
   

- Advertisement -