Hi smile,
Check the below modified query.
SQL
declare @StdID varchar(50)
Set @StdID= 'R-0003'
select * into #TempMarks
from (
select *
from (
select [SubjectID],[SetExamID],[Marks]
from tblSetMarks
where AdmissionNo= @StdID
)
as tbl
pivot (sum(Marks) for [SetExamID] in ([14],[15])
) as PVT
) as s
select CONVERT(VARCHAR(20),SubjectID) SubjectID,[14],[15],[14]+[15] as 'Grand Total' from #TempMarks
union all
select 'Total', sum([14]), sum ([15]), sum ([14]+[15]) from #TempMarks
drop table #TempMarks
Output
SubjectID |
14 |
15 |
Grand Total |
12 |
21 |
29 |
50 |
Total |
21 |
29 |
50 |