Hi smile,
Refer below test query.
SQL
DECLARE @Test AS TABLE(AdmissionNo VARCHAR(10),Recievable INT,NetBal INT,Paid INT,RemBal INT,Month VARCHAR(10),Date VARCHAR(10))
INSERT INTO @Test VALUES('R-01',700,700,700,0,'Aug','24.08.2018')
INSERT INTO @Test VALUES('R-02',700,700,500,200,'Aug','24.08.2018')
INSERT INTO @Test VALUES('R-03',700,700,400,300,'Aug','24.08.2018')
INSERT INTO @Test VALUES('R-04',700,0,0,0,'Aug','24.08.2018')
INSERT INTO @Test VALUES('R-05',700,0,0,0,'Aug','24.08.2018')
INSERT INTO @Test VALUES('R-01',500,500,400,100,'Sep','24.09.2018')
INSERT INTO @Test VALUES('R-02',500,500,300,200,'Sep','24.09.2018')
INSERT INTO @Test VALUES('R-03',500,500,200,300,'Sep','24.09.2018')
INSERT INTO @Test VALUES('R-04',500,0,0,0,'Sep','24.09.2018')
INSERT INTO @Test VALUES('R-05',500,0,0,0,'Sep','24.09.2018')
SELECT AdmissionNo,SUM(Recievable)Recievable,SUM(NetBal)NetBal,SUM(Paid)Paid,SUM(RemBal)RemBal
FROM @Test
GROUP BY AdmissionNo
Output
AdmissionNo |
Recievable |
NetBal |
Paid |
RemBal |
R-01 |
1200 |
1200 |
1100 |
100 |
R-02 |
1200 |
1200 |
800 |
400 |
R-03 |
1200 |
1200 |
600 |
600 |
R-04 |
1200 |
0 |
0 |
0 |
R-05 |
1200 |
0 |
0 |
0 |