0

I would like to seek some help in debugging this SQL query. I would like to join 3 tables/sheets as I am creating this in Excel VBA.

SELECT
    [A-TFN], [Title], [First Name], [Middle Name], [Last Name], [Gender],
    [Date of Birth], [Address 1], [Address 2], [City], [Postal Code], [State],
    [Employment Date], [Benefit Base Salary], [On Plan?]
FROM [Report 1$A9:P9756] e
INNER JOIN [Report 2$A11:C9761] c
    ON c.[Home NUM] = e.[Home NUM]
INNER JOIN [Report 3$A3:B6682] i
    ON i.[Employee Id] = e.[Home NUM]
WHERE (e.[Home NUM] LIKE '%123123123%') OR (e.[Host NUM] LIKE '%123123123%');

Set obj_res = obj_con.Execute(str_sqlquery)

It works fine when joining 2 tables but when I added the INNER JOIN for Report 3, I get the syntax error (missing operator) in query expression.

It displays error in this part

c.[Home NUM] = e.[Home NUM] INNER JOIN [Report 3$A3:B6682] i ON i.[Employee Id] = e.[Home NUM]

Thank you.

1 Answer 1

2

In Access SQL syntax, you need to place the first inner join in parentheses, like this:

SELECT
    [A-TFN], [Title], [First Name], [Middle Name], [Last Name], [Gender],
    [Date of Birth], [Address 1], [Address 2], [City], [Postal Code], [State],
    [Employment Date], [Benefit Base Salary], [On Plan?]
FROM
(
    [Report 1$A9:P9756] e
    INNER JOIN [Report 2$A11:C9761] c
        ON c.[Home NUM] = e.[Home NUM]
)
INNER JOIN [Report 3$A3:B6682] i
    ON i.[Employee Id] = e.[Home NUM]
WHERE (e.[Home NUM] LIKE '%123123123%') OR (e.[Host NUM] LIKE '%123123123%');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.