Hi there,
I'm fairly new to access and am finding some of the table joins a bit tricky.
I have a design view statement defined that queries multiple tables for information based on the contents of another table.
I now need to query the tables from within an excel database.
If I build the SQL statements individually I can query access successfully using VBA and ADODB.Recordset functions.
But when I try and build one statement with multiple table joins, which queries each table and either returns a value of nil I can't figure it out.
Example, I wish to query each table within the below statement for a user ID e.g. 1000101 and it will return a hit for each table that it finds a match in.
I'm unsure how to pass in the ID to each table?
any help/pointers very much appreciated.
Cheers
Bug
I'm fairly new to access and am finding some of the table joins a bit tricky.
I have a design view statement defined that queries multiple tables for information based on the contents of another table.
I now need to query the tables from within an excel database.
If I build the SQL statements individually I can query access successfully using VBA and ADODB.Recordset functions.
But when I try and build one statement with multiple table joins, which queries each table and either returns a value of nil I can't figure it out.
Example, I wish to query each table within the below statement for a user ID e.g. 1000101 and it will return a hit for each table that it finds a match in.
I'm unsure how to pass in the ID to each table?
any help/pointers very much appreciated.
Cheers
Bug
Code:
[FONT=Arial][FONT=Arial]sSQL = "SELECT HRTABLE.[First names], HRTABLE.[Last name], HRTABLE.[E-mail address], BUSINESSLeavers.[Date of Leaving], " & _[/FONT]
[FONT=Arial]"HRTABLE.[Org Unit ID], HRTABLE_1.[First names], HRTABLE_1.[Last name], HRTABLE_1.[E-mail address], " & _[/FONT]
[FONT=Arial]"BUSINESSLevels.[BUSINESS LEVEL (Equivalent Standard Level)], HRTABLE.[Org Unit 1 ID], HRTABLE_2.[First names], " & _[/FONT]
[FONT=Arial]"HRTABLE_2.[Last name], HRTABLE_2.[E-mail address], BUSINESSLevels_1.[BUSINESS LEVEL (Equivalent Standard Level)], " & _[/FONT]
[FONT=Arial]"SMART.PID, SMART.Forename, SMART.Surname, SMART.Email, SMART.[Reports to ID], SMART_1.Forename, SMART_1.Surname, " & _[/FONT]
[FONT=Arial]"SMART_1.Email, BUSINESSLevels_2.[BUSINESS LEVEL (Equivalent Standard Level)], OTHERCOMPANYHR.[First Name], OTHERCOMPANYHR.Surname, " & _[/FONT]
[FONT=Arial]"OTHERCOMPANYHR.[Supervisor Empno], OTHERCOMPANYHR_1.[First Name], OTHERCOMPANYHR_1.Surname, OTHERCOMPANYLevels.grade_band, OTHERCOMPANYLevels.grade_level " & _[/FONT]
[FONT=Arial]"FROM BUSINESSLeavers, (((HRTABLE LEFT JOIN HRTABLE AS HRTABLE_1 ON HRTABLE.[Org Unit ID] = HRTABLE_1.Persno) " & _[/FONT]
[FONT=Arial]"LEFT JOIN HRTABLE AS HRTABLE_2 ON HRTABLE.[Org Unit 1 ID] = HRTABLE_2.Persno) " & _[/FONT]
[FONT=Arial]"LEFT JOIN BUSINESSLevels ON HRTABLE.[Org Unit ID] = BUSINESSLevels.Persno) " & _[/FONT]
[FONT=Arial]"LEFT JOIN BUSINESSLevels AS BUSINESSLevels_1 ON HRTABLE.[Org Unit 1 ID] = BUSINESSLevels_1.Persno, " & _[/FONT]
[FONT=Arial]"SMART LEFT JOIN SMART AS SMART_1 ON SMART.[Reports to ID] = SMART_1.PID, " & _[/FONT]
[FONT=Arial]"LEFT JOIN BUSINESSLevels AS BUSINESSLevels_2 ON SMART.[Reports to ID] = BUSINESSLevels_2.Persno, " & _[/FONT]
[FONT=Arial]"OTHERCOMPANYHR LEFT JOIN OTHERCOMPANYHR AS OTHERCOMPANYHR_1 ON OTHERCOMPANYHR.[Supervisor Empno] = OTHERCOMPANYHR_1.[File Number]), " & _[/FONT]
[FONT=Arial]"LEFT JOIN OTHERCOMPANYLevels ON OTHERCOMPANYHR.[Supervisor Empno] = OTHERCOMPANYLevels.file_number"[/FONT]
[/FONT]