I have a table for Creditors and a table for all their CreditorTransactions, a table for Debtors and a table for all their DebtorTransactions. I need to calculate (in different fields) the total transaction amounts for each, such as in :
Take all the Creditors, put their Names in field(0), their InvoiceTotals in field(1) and their CreditNoteTotals in field(2)and union this with all the Debtors, put their Names in field(0), the sum of their InvoiceTotals in field(3) and the sum of their CreditNoteTotals in field(4).
This is far too complicated for me to even try, but I will :
SELECT
Creditors.Credname,
SUM(CreditorTransactions.amount)as CredInvoiceTotals where TransType=1,
SUM(CreditorTransactions.amount) as CredCreditNoteTotals where TransType=2
FROM Creditors
INNER JOIN
CreditorTransactions
ON
Creditors.ID=CreditorTransactions.CredID
WHERE
CreditorTransactions.Transdate<=Mydate (parameter)
UNION
Debtors.Debtorname,
SUM(DebtorTransactions.amount) AS DebtorInvoiceTotals WHERE
TransType=1,
SUM(DebtorTransactions.amount) as DebtorCreditNoteTotals WHERE TransType=2
FROM
Debtors
INNER JOIN
DebtorTransactions
ON
Debtors.ID=DebtorTransactions.DebtorID WHERE DebtorTransactions.Transdate<=MyDate
... and this is about as far as I can go.
The TransactionTypes are available in the Transactions table as a field called TransType where 1 refers to invoices and 2 refers to credit notes.
I know its a tall order, but help will be appreciated.
Thanks
Take all the Creditors, put their Names in field(0), their InvoiceTotals in field(1) and their CreditNoteTotals in field(2)and union this with all the Debtors, put their Names in field(0), the sum of their InvoiceTotals in field(3) and the sum of their CreditNoteTotals in field(4).
This is far too complicated for me to even try, but I will :
SELECT
Creditors.Credname,
SUM(CreditorTransactions.amount)as CredInvoiceTotals where TransType=1,
SUM(CreditorTransactions.amount) as CredCreditNoteTotals where TransType=2
FROM Creditors
INNER JOIN
CreditorTransactions
ON
Creditors.ID=CreditorTransactions.CredID
WHERE
CreditorTransactions.Transdate<=Mydate (parameter)
UNION
Debtors.Debtorname,
SUM(DebtorTransactions.amount) AS DebtorInvoiceTotals WHERE
TransType=1,
SUM(DebtorTransactions.amount) as DebtorCreditNoteTotals WHERE TransType=2
FROM
Debtors
INNER JOIN
DebtorTransactions
ON
Debtors.ID=DebtorTransactions.DebtorID WHERE DebtorTransactions.Transdate<=MyDate
... and this is about as far as I can go.
The TransactionTypes are available in the Transactions table as a field called TransType where 1 refers to invoices and 2 refers to credit notes.
I know its a tall order, but help will be appreciated.
Thanks