0

Help, I'm new to SQL, and new to Stack Overflow!

I am receiving a "Syntax Error", which only seems to occur with the 2nd Left Join (without it, the code runs fine). Here is my code, being compiled by Access 2010:

SELECT      Billings.[CustomerNumber], 
            Billings.[Customer Name], 
            Billings.[SOP Number], 
            Billings.[Item Number], 
            Sum (Billings.[Extended Price]) AS ['Revenue'], 
            Sum (Billings.QTY) AS ['Quantity']
FROM        [Product Codes]         AS Codes
LEFT JOIN   Billings                ON Codes.[Product Code] = Billings.[Item Number]
LEFT JOIN   [All Rep Assignments]   ON Billings.CustomerNumber = [All Rep Assignments].[Account Number]
GROUP BY    Billings.[CustomerNumber], 
            Billings.[Customer Name], 
            Billings.[SOP Number], 
            Billings.[Item Number]
Smandoli
  • 6,919
  • 3
  • 49
  • 83

2 Answers2

0

If your SQL as shown is from the Access query builder using SQL view, be aware Access is sensitive about white-space. Make sure your lines end with a space. (I notice there is no semi-colon at the end, which is required in that view.)

If your code is from somewhere else, like a VBA module, then move that SQL over to the Access query builder using SQL view and trouble-shoot from there. (With a semi-colon at the end.) See here for more.

Community
  • 1
  • 1
Smandoli
  • 6,919
  • 3
  • 49
  • 83
0

You need parentheses when having multiple joins (1 for each)

SQL multiple join statement

SELECT      Billings.[CustomerNumber], 
            Billings.[Customer Name], 
            Billings.[SOP Number], 
            Billings.[Item Number], 
            Sum (Billings.[Extended Price]) AS ['Revenue'], 
            Sum (Billings.QTY) AS ['Quantity']
FROM        (([Product Codes]         AS Codes
LEFT JOIN   Billings                
ON Codes.[Product Code] = Billings.[Item Number])
LEFT JOIN   [All Rep Assignments]   
ON Billings.CustomerNumber = [All Rep Assignments].[Account Number])
GROUP BY    Billings.[CustomerNumber], 
            Billings.[Customer Name], 
            Billings.[SOP Number], 
            Billings.[Item Number]
Community
  • 1
  • 1
Mark C.
  • 6,332
  • 4
  • 35
  • 71