Clients (CustomerID, ......)
Invoice (CustomerID, InvoiceNumber, DatePurchased, Discount)
InvoiceItem (Product, InvoiceNumber, UnitPrice, Quantity)
Payment (InvoiceNumber, Payment Received, DateReceived)
I am trying to list down clients which have invoices that has not been settled. There is a 10% tax charged and the final amount would be rounded off. Here is what I've gotten so far
CODE
SELECT * FROM Clients WHERE [CustomerID] IN (
SELECT [CustomerID] FROM Invoice WHERE [InvoiceNumber] IN (
SELECT a.[InvoiceNumber] FROM Invoice a, InvoiceItem b, Payment c WHERE
a.[InvoiceNumber] = b.[InvoiceNumber] AND
a.[InvoiceNumber] = c.[InvoiceNumber]
GROUP BY a.[InvoiceNumber]
HAVING (ROUND(1.1*SUM(b.[UnitPrice] * b.[Quantity]), 0) - a.[Discount] - SUM(c.[Payment Received]) > 0
)
);
I've been working on this for days and all i got is Missing ), ], or Item in query expression
Any help is greatly appreciated.