Total columns and rows

Giganews Newsgroups
Subject: Total columns and rows
Posted by:  tshad (t…@dslextreme.com)
Date: Tue, 26 Oct 2010

I am doing a pivot where the sql is dynamic as I don't know the column names
until done.

But I am trying to get totals for my rows and totals for my columns (the
pivoted columns).

How would I do that if I have the following:

I am using:

SET @sql = '
select * from #tfs
PIVOT
(
    SUM(Number)
    for retailer in('+@strList+')
) as pvt
'

To get.

select * from #tfs
PIVOT
(
SUM(Number)
for retailer in([Sears], [CompUSA], [Lowes], [None], [K-Mart])
) as pvt

Thanks,

Tom

Replies