on 2024 Dec 12 9:14 AM
If I use this statement
SELECT SUM(Debit) - SUM(Credit) FROM A_Purchase_Ledger WHERE Supplier_ID = 16
It returns 0 as the sum of debit is 250 and the sum of credit is 250. However, in this...
SELECT A_Purchase_Ledger.Supplier_ID AS 'SupplierID',
A_Purchase_Ledger.Credit AS 'Credit',
A_Purchase_Ledger.Document_Date AS 'DocDate',
A_Purchase_Ledger.P_Description As 'DocDesc',
A_Purchase_Ledger.Document_No AS 'DocNumber',
Suppliers.Bank_BankName AS 'BankName',
Suppliers.Bank_RoutingNumber AS 'RoutingNumber',
Suppliers.Bank_AccountName AS 'AccountNumber',
Suppliers.Bank_AccountName AS 'AccountName',
Suppliers.Due_Days AS 'DueDays',
(SELECT(SUM(A_Purchase_Ledger.Credit) - SUM(A_Purchase_Ledger.Debit))WHERE A_Purchase_Ledger.Supplier_ID = SupplierID) as 'TotalBalance'
FROM A_Purchase_Ledger
INNER JOIN Suppliers ON A_Purchase_Ledger.Supplier_ID = Suppliers.Supplier_ID
WHERE A_Purchase_Ledger.Paid = 'N' AND A_Purchase_Ledger.Hold = 0 AND
A_Purchase_Ledger.eCheck_Pending = 0 AND A_Purchase_Ledger.eSig_Required = 0
AND Type = 'PI' AND dateadd(day,Suppliers.Due_Days, A_Purchase_Ledger.Document_Date) <= current date
GROUP BY A_Purchase_Ledger.Supplier_ID, Credit, Document_Date, P_Description, Document_No, Bank_BankName, Bank_RoutingNumber, Bank_BankName, Bank_AccountName, Due_Days
It returns 250.00. Any ideas what the heck I am doing wrong?
Thanks
Request clarification before answering.
Sometimes after you have stared at something for hours nothing pops up until you ask for help
(SELECT SUM(A_Purchase_Ledger.Credit)- SUM(A_Purchase_Ledger.Debit)FROM A_Purchase_Ledger WHERE A_Purchase_Ledger.Supplier_ID = SupplierID) as 'TotalBalance'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
52 | |
6 | |
6 | |
6 | |
5 | |
5 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.