0

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 ...

Imagem em Excel IMG1

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 

SQL

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Does this answer your question? [Calculate a Running Total in SQL Server](https://stackoverflow.com/q/860966/2029983) If not, why not? Sample data and expected results (not images) will help us help you if so as well. – Thom A Dec 08 '20 at 10:44
  • I'm lost. There is no column called "balance". – Gordon Linoff Dec 08 '20 at 11:48
  • Thank you very much, for the indication of the link, it works perfectly. @Larnu – Kevin Kafala Dec 09 '20 at 08:49

0 Answers0