Create Table #Temp
(
sno Int,
Sname varchar(40),
Marks Int
)
Insert into #Temp
Values(001,'abcde',90),(002,'fghij',80),(003,'lmnop',70),(004,'qrstu',60),(005,'vwxyz',50)
;with cte
as
(
Select sno,Sname,Marks,ROW_NUMBER() Over(Order by Sno) rno From #Temp
)
Select st.sno,st.Sname,st.Marks,COALESCE(CONVERT(VARCHAR,t.Total),'--') [Total] from cte st
left outer join (Select sum(Marks) [Total],max(rno) [rno] From cte ) t
on t.rno=st.rno
Drop Table #Temp
Output:
sno Sname Marks Total
1 abcde 90
2 fghij 80
3 lmnop 70
4 qrstu 60
5 vwxyz 50 350