Hi smile,
Refer the below test query.
SQL
DECLARE @tblStdReg AS TABLE(AdmissionNo VARCHAR(10),SName VARCHAR(10),FName VARCHAR(10),Status VARCHAR(10))
INSERT INTO @tblStdReg VALUES('R-001','ABC','SKY','Active')
INSERT INTO @tblStdReg VALUES('R-002','SKY','ABC','Active')
INSERT INTO @tblStdReg VALUES('R-003','XYZ','MNO','In Active')
DECLARE @tblFeesCollection AS TABLE(AdmissionNo VARCHAR(10),VoucherNo VARCHAR(10),Total INT,Paid INT,RemBal INT)
INSERT INTO @tblFeesCollection VALUES('R-001','VC-0001',1000,700,300)
SELECT sr.AdmissionNo,sr.SName,sr.FName,fc.VoucherNo,fc.Paid,fc.RemBal,sr.Status
FROM @tblFeesCollection as fc
RIGHT OUTER JOIN @tblStdReg as sr on fc.AdmissionNo=sr.AdmissionNo
Output
AdmissionNo |
SName |
FName |
VoucherNo |
Paid |
RemBal |
Status |
R-001 |
ABC |
SKY |
VC-0001 |
700 |
300 |
Active |
R-002 |
SKY |
ABC |
NULL |
NULL |
NULL |
Active |
R-003 |
XYZ |
MNO |
NULL |
NULL |
NULL |
In Active |