|
|
Question : Missing Operator performing multiple inner joins
|
|
I'm building an sql statement through code in visual basic for an ms access database. The statement is created as a user selects fields from various tables. It works fine for 2 tables, but once a third table is introduced I get the following error:
Run-time error '-2147217900 (80040e14) Syntax error (missing operator) in query expression
Here is the code that it is executing when it happens:
SELECT Tbl_Members.MemberID, Tbl_Member_History.Initiated_Date, Tbl_Partner.Name FROM Tbl_Members Inner Join Tbl_Member_History ON (Tbl_Members.MemberID = Tbl_Member_History.MemberID) Inner Join Tbl_Partner ON (Tbl_Member_History.MemberID = Tbl_Partner.MemberID)
It does not matter what fields or tables, as soon as there is more than 2 tables selected it gives the error. Also, as far as syntax, I've tried with and without the parenthesis.
Can anyone tell me what is wrong? Thanks.
|
Answer : Missing Operator performing multiple inner joins
|
|
Q: I'm having a little trouble because I'm doing it through vb. Basically, assuming that there are many tables in the query, what part of the sql statement needs parenthesis? ---
Put parentesis around the entire nested join. Like so: (A join B on A.id=B.id)
Everytime you add another table, add another layer of parenthesis.
((((A join B on A.a=B.a) join C on B.b=C.b) join D on C.c=D.c) join E on D.d=E.d) ...
A little more obscure, but equally valid is to nest the other way.
(E join (D join (C join (B join A on A.a=B.a) on B.b=C.b) on C.c=D.c) on D.d=E.d) ...
|
|
|
|
|