I have a Query made that takes all invoices from a specific customer and it shows all the payment information and current balance, as shown in the image of excel Ex: Img1
The idea is to add the missing values in the column balance Ex:
Missing Value is 0 + 518820 = 518820 Balance; 518820 + 2777750 = 796570 Balance And so on ...
Here are my scripts that I created to do the exercise. THE TABLES THAT ARE BEING WORKED ARE BILLING (ft) AND CURRENT ACCOUNT (cc)
SELECT ft.nmdoc, ft.fno, ft.fdata, ISNULL(cc.deb,cc.cred) "Valor Doc", ISNULL(cc.debf,cc.credf)Valor_Pago,
ISNULL((cc.deb-cc.debf),(cc.cred-cc.credf)) Valor_em_Falta,
ISNULL(++(cc.deb-cc.debf),(cc.cred-cc.credf)) Saldo,
--ISNULL(SUM(@saldo ),0),
ft.pdata Dt_Vencimento
FROM cc RIGHT JOIN ft ON cc.ftstamp=ft.ftstamp
where ft.nome ='JOAQUIM TESTE & FILHO,LDA'
GROUP BY ft.nmdoc, ft.fno, ft.fdata,ft.pdata ,cc.deb,cc.cred,cc.debf,cc.credf
order by ft.fdata