UNION ALL SELECT spin,sname,sdesignation,LonNo,SanctionAmt,disversdate,LoanId,LoanName+' ('+LoanId+')' as LoanName ,FlatYN=case when LnsFlatYN=1 then 'Yes' else 'No' end ,FlatIntPercent=case when LnsFlatYN=1 then 'Flat Int. Rate : '+cast(LnsFlatIntPercent as varchar) else '' end ,LnsReduceIntPercent,year(l.LfrGenDate) fyear, MONTH(l.LfrGenDate) fmonth,l.LfrPrinOutstanding AS openbal, (l.LfrPrinOutstanding+l.LfrIntOutstanding) as installment,l.LfrRealizationAmt-l.LfrPrinOutstanding Interest, l.LfrPrinOutstanding principal, 0 as DisburseAmt, (l.LfrPrinOutstanding+l.LfrIntOutstanding-l.LfrRealizationAmt) closebal,a.stlCompoundInterval FROM #StaffInfo a inner join LnLoanFinalRealization l ON a.LonNo = l.LfrStlSlNo WHERE LfrStlSlNo = @LoanNO ORDER by fyear,fmonth