I have the query below:
- SELECT sum(c.ConvertedNetPremium + c.ConvertedVAT + c.ConvertedRegistryFee) as Due
- from dbo.CashierSalesDetails c
- select sum(a.AmountPaid) as payment
- from dbo.tblAgentPaymentMonitoring a
My requirement is that, I should be able to deduct the "payment" from the "Due". below is the actual data of both tables
I tried this code but the answer is wrong:
- SELECT a.TaxInvoiceNumber, sum(a.AmountPaid) as payment, sum(c.ConvertedNetPremium + c.ConvertedVAT + c.ConvertedRegistryFee) as Due,
- sum(a.AmountPaid) - sum(c.ConvertedNetPremium + c.ConvertedVAT + c.ConvertedRegistryFee) as BAlance
- FROM dbo.tblAgentPaymentMonitoring a INNER JOIN
- dbo.CashierSalesDetails c ON a.TaxInvoiceNumber = c.TaxInvoiceNumber
- GROUP BY a.TaxInvoiceNumber


Nitin SontakkePosted Mar 22, 2017, 2:02 AM
Nitin SontakkePosted Mar 23, 2017, 12:41 AM
Jes SiePosted Mar 23, 2017, 12:32 AM
Nitin Sontakke Thank you so much! Now I understand. May I ask why in the where clause you use 1 = 1?
Jes SiePosted Mar 22, 2017, 1:31 AM
Nitin SontakkePosted Mar 21, 2017, 7:08 AM
Jes SiePosted Mar 21, 2017, 6:29 AM
Nitin Sontakke the joining column is TaxInvoiceNumber. Below is the script:
Nitin SontakkePosted Mar 21, 2017, 6:25 AM