Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need a simpler SQL than this
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00748637
Message ID:
00749223
Views:
24
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
Map
View

Click here to load this message in the networking platform