Hey,I have been asked to add some summary rows and columns to my cross tab report.This is some sample code that is used to generate the crosstab at the moment. Please note the user gets to choose the fields and calculation of their report so the following code is generated by my class:SELECT *FROM (SELECTSelection1_tblTemplate.TemplateCategory + '/' + Selection1_tblTemplate.TemplateType as [ScorecardItem.Template],Selection1_tblMeasure.MeasureName as [ScoreItem.Measure],CAST(CAST (YEAR(Selection1_tblScorecard.DateAssessed) as varchar(4)) + ' ' + CAST (DATENAME(mm, Selection1_tblScorecard.DateAssessed) AS varchar(3)) AS nVarchar) as [Column],CASE Selection1_tblScore.DirectEntry WHEN 2 THEN Selection1_tblScore.ActualScore ELSE (Selection1_tblScore.ActualScore - Selection1_tblMeasure.WorstScore) / (Selection1_tblMeasure.BestScore - Selection1_tblMeasure.WorstScore) * 100 END as CalcFieldFROM tblScore as Selection1_tblScoreINNER JOIN tblMeasure as Selection1_tblMeasure ON Selection1_tblMeasure.MeasureID = Selection1_tblScore.MeasureIDINNER JOIN tblScorecard as Selection1_tblScorecard ON Selection1_tblScorecard.ScorecardID = Selection1_tblScore.ScorecardIDINNER JOIN tblTemplate as Selection1_tblTemplate ON Selection1_tblTemplate.TemplateID = Selection1_tblScorecard.TemplateIDWHERE(1 = 1)ANDSelection1_tblTemplate.TemplateID IN (4)) AS sPIVOT ( AVG(CalcField) FOR [Column] IN ([2006 Jan],[2006 Feb],[2006 Mar],[2006 Apr],[2006 May],[2006 Jun],[2006 Jul],[2006 Aug],[2006 Sep],[2006 Oct],[2006 Nov],[2006 Dec],[2007 Jan],[2007 Feb],[2007 Mar],[2007 Apr],[2007 May],[2007 Jun],[2007 Jul],[2007 Aug],[2007 Sep],[2007 Oct],[2007 Nov],[2007 Dec],[2008 Jan],[2008 Feb],[2008 Mar])) AS pORDER BY[ScorecardItem.Template],[ScoreItem.Measure]
The summary rows and columns they want to add are AVG, SUM, Best and Worst. Each of these will be optional.How can I use SQL to generate these as part of the above, is it even possible?I have considered simply adding these columns when I "draw" the output but this is not possible with the AVG, unless you wanted the AVG of the Averages which they do not want.Any help is welcomed. 