PSB (12/18/2013)
Fi,I have a table with the Group name and Total Count by group . I need to add a 'Total' and summation of all counts at the end .
CREATE TABLE #TempTable
(GroupName VARCHAR(10),NumberOfCases INT )
INSERT INTO #Temp Table (GroupName,NumberOfCases)
VALUES ('Grp A',10)
INSERT INTO #Temp Table (GroupName,NumberOfCases)
VALUES ('Grp B',20)
SELECT * from #TempTable
I want the result to be like the below :
Grp A 10
Grp B 20
Total 30
Thanks,
PSB
Hope following will give you the better solution...
with cte as (
select groupname ,SUM(numberofcases)numberofcases from #TempTable group by groupname with rollup
)
select isnull (GROUPname , 'Total' )GROUPname ,numberofcases from cte