views:

222

answers:

2

Dear fellow members,

It's nice to find such a useful site with genius members. I have been trying to find a solution for this SQLITE problem for a while now. Google didn't help me, except in finding this website. The SQL query works fine on the MSAccess version of the same database.

Here's my SQL statement - which didn't work for me.


SELECT Invoices.InvoiceNumber, Invoices.Quantity,Invoices.Code, Invoices.Price,Invoices.Discount, Invoices.InvoiceGrandTotal, Employees.EmployeeName, Customers.CustomerName, Invoices.DateOfInvoice, [price]*[Quantity] AS Total, Customers.Address, Products.Description,Products.Unit  
    FROM Products 
        INNER JOIN (
            (   
                ( Invoices INNER JOIN InvoiceDetails 
                    ON Invoices.InvoiceNumber = InvoiceDetails.InvoiceNumber
                ) INNER JOIN Customers 
                    ON Invoices.CustomerID = Customers.CustomerID
            ) INNER JOIN Employees 
                ON Invoices.UserID = Employees.EmployeeID
        ) ON Products.Code = InvoiceDetails.Code  
    WHERE (((InvoiceDetails.InvoiceNumber)='10111'));

The error message is: "Cannot compile Select-Statement: no such column: Invoices.InvoiceNumber"

+3  A: 

That usually just means that you mis-spelled the column name ... check your Invoices table and make sure the column is InvoiceNumber and not "Invoice_Number" or something similar ...

Also, a much simpler version of this query would look something like this .. without all the strange nesting:

SELECT 
   Invoices.InvoiceNumber, 
   Invoices.Quantity,
   Invoices.Code, 
   Invoices.Price,
   Invoices.Discount, 
   Invoices.InvoiceGrandTotal, 
   Employees.EmployeeName, 
   Customers.CustomerName, 
   Invoices.DateOfInvoice, 
   [price]*[Quantity] AS Total, 
   Customers.Address, 
   Products.Description,
   Products.Unit 
FROM
   Invoices

   JOIN Employees 
      ON Employees.EmployeeID = Invoices.UserID 

   JOIN Customers 
      ON Customers.CustomerID = Invoices.CustomerID

   JOIN InvoiceDetails 
      ON InvoiceDetails.InvoiceNumber = Invoices.InvoiceNumber

   JOIN Products
      ON Products.Code = InvoiceDetails.Code

WHERE 
   InvoiceDetails.InvoiceNumber = '10111'
Ron Savage
+1 for cleaning up the garbage sql into something infinitely more readable.
Chris Lively
Thanks Ron Savage, I owe you a lot. Your SQL statement works perfectly.
Shaamil
Glad to be able to help!
Ron Savage
Shaamil, if this works, please accept the answer as the correct one. Click the white checkmark on this answer so Ron gets rep, and future visitors to this question will quickly see what the right answer is.
Mike Sherov
A: 

I think the issue might be with case sensitivity. Unless I'm mistaken, MS Access field names are not case sensitive. Check the offending column name for the correct casing in you SQLITE table definition.

Mike Sherov