SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to add a grand total column to pivottable


how to add a grand total column to pivottable

Author
Message
Sarsoura
Sarsoura
SSC Veteran
SSC Veteran (240 reputation)SSC Veteran (240 reputation)SSC Veteran (240 reputation)SSC Veteran (240 reputation)SSC Veteran (240 reputation)SSC Veteran (240 reputation)SSC Veteran (240 reputation)SSC Veteran (240 reputation)

Group: General Forum Members
Points: 240 Visits: 164
I would like to add a grand total column (total number of students) to a pivot table the pivot table uses count(studentid)
DECLARE @SLOAchievement nvarchar(1000)
SELECT @SLOAchievement =
STUFF(
(
select ',[' + AchievementLevel
+ ']'
from SLO. OrgAchievementLevel
where OrgID=@OrgID





for xml path('')
),
1,1,''
)
declare @mysql varchar(1000)
set @mysql=
N'select * from
(select TP.SLOID,
tp.Studentid as studentid,
ts.SLOText,
C.achievementLevel as Achievement
from '+'#'+'TempPerc TP
cross apply
dbo.fn_NewSLO_Org_Achievement_inline('+cast(@orgID as varchar(10))+
',TP.yourpercent) as C
inner join '+'#'+
'tempSLO as Ts '+
'on
tp.SLOID=ts.SLOID
)
Data
PIVOT (
count(StudentID) FOR Achievement
IN (
' + @SLOAchievement +'
) ) PivotTable'
Conficker
Conficker
SSC Veteran
SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)

Group: General Forum Members
Points: 259 Visits: 386
Insert all data into Temp table and do accorndingly.
damodharan-402092
damodharan-402092
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 82
Try using Pivot. Follow the link for example

http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search