Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Left Join in Query. 1

Status
Not open for further replies.

lars7

Technical User
Aug 16, 2005
817
GB
Hi I'm trying to add a third table to my query but I am getting a symtax error. Can anyone show me how to fix it.

strSQL = "Select * FROM [tbltruststaff] LEFT JOIN [Service Descriptions] ON [tbltruststaff].DIV = [Service Descriptions].D_DIV LEFT JOIN [Discipline Descriptions] ON [tbltruststaff].DISCIPLINE = [Discipline Descriptions].D_DISCIPLINE" _

It works well with the first left join but not the second.
 
You need parentheses
Code:
strSQL = "Select * FROM [COLOR=red]([/color][tbltruststaff] LEFT JOIN [Service Descriptions] ON [tbltruststaff].DIV = [Service Descriptions].D_DIV [COLOR=red])[/color] LEFT JOIN [Discipline Descriptions] ON [tbltruststaff].DISCIPLINE = [Discipline Descriptions].D_DISCIPLINE"
 
hi Golam,
I tried that but still "(the missing operator) in query expression" message. I have a few where's in the code too, could this cause the error:

strSQL = "Select * FROM ([tbltruststaff] LEFT JOIN [Service Descriptions] ON [tbltruststaff].DIV = [Service Descriptions].D_DIV) LEFT JOIN [Discipline Descriptions] ON [tbltruststaff].DISCIPLINE = [Discipline Descriptions].D_DISCIPLINE" _
& "Where tbltrustStaff.
is null AND " _
& "tbltruststaff.[additpayno] = '1' and " _
& "tbltruststaff.[grade] <>'bn' and " _
& "tbltruststaff.[grade] <>'EXEC LVL 4' and " _
& "tbltruststaff.[grade] <>'EXEC LVL 5' and " _
& "tbltruststaff.[grade] <>'EXEC LVL 6' and " _
& "tbltruststaff.[grade] <>'EXEC LVL 7' and " _
& "tbltruststaff.[grade] <>'EXEC LVL 8' and " _
& "tbltrustStaff.[transfer] = 0 " _
& strwhere

This is the line that's showing in the error message:


[tbltruststaff].DISCIPLINE = [Discipline Descriptions].D_DISCIPLINE" _
& "Where tbltrustStaff.
is null AND " _​
 
I have just commented out all the Where's in the query and it worked but i need to keep them, has anyone any suggestions.
 
Hi,
I got it to work. I changed the join to an Inner and it worked. Thanks Golom for the parentheses.
 
Now you're missing a space
Code:
Descriptions].D_DISCIPLINE[COLOR=red yellow] [/color]" _
        & "Where tbltrustStaff.[left] is null AND " _
 
I must have changed that when I was copying and pasting things in, it's gone now.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top