|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, December 05, 2012 11:31 AM
Points: 74,
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'
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 5:36 AM
Points: 58,
Visits: 243
|
|
| Insert all data into Temp table and do accorndingly.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 5:33 AM
Points: 3,
Visits: 36
|
|
Try using Pivot. Follow the link for example
http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
|
|
|
|