General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Hi Rob,
Try:
SELECT invoices.*, ;
NVL(sum(InvoiceLines.Amount),00000000.00) AS InvAmount, ;
NVL(SUM(Credits.Amount),000000000.00) AS credAmount, ;
NVL(SUM(Refunds.Amount),00000000.00) AS RefuAmount, ;
Contracts.ContractNumber, Contracts.Description as Contracts_Description, Contracts.ContractTotal, ;
ContractHeaders.ContractHeaderID, ;
Customers.CustomerID, Customers.LastName ;
from invoices ;
LEFT OUTER JOIN Contracts on Contracts.ID = invoices.ContractsID ;
LEFT OUTER JOIN ContractHeaders on contractHeaders.ID = Contracts.ContractHeadersID;
LEFT OUTER JOIN Customers ON Customers.ID = contractheaders.CustomersID ;
LEFT OUTER JOIN InvoiceLines on InvoiceLines.invoicesId = Invoices.ID ;
LEFT OUTER JOIN Credits on credits.invoicesId = Invoices.ID;
LEFT OUTER JOIN Refunds ON refunds.invoicesId = Invoices.ID;
GROUP by Invoices.InvoiceID ;
ORDER by Invoices.InvoiceID ;
WHERE ??my whereclause??;
INTO CURSOR mycursor
You may need a second query for sorting. Let me know if this works, I wasn't going to create the tables to test it <g>. I think I've messed the field names up in the join conditions, but I'm sure that you get the idea.
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only