SQL statements in VBA - Problems with Inner Join and Outer Join (4 tables)

absundo

New Member
Joined
Jan 30, 2015
Messages
23
I am using SQL statements in VBA and I am having trouble joining 4 tables located in separate worksheets named "Stn", "Db", "Param" and "Ol"

I have 4 tables:

  1. "Stn" with headers: Station_Name, Station_Abbreviation, Station_Order
  2. "Db" with headers: Station_Name, Sample_Date, Parameter_Name, Concentration
  3. "Param" with headers: Parameter_Name, Parameter_Abbreviation
  4. "OL" with headers: Station_Abbreviation, Sample_Date, Parameter_abbreviation, Concentration and Flag

The final table I want is : Station_abbreviation, parameter_abbreviation, Sample_date, Concentration and Flag
Not all the data have Flags, so I want to use an outer join and have it return all data even the ones without a "flag"

Code:
strSourceSht = "[db$]"
strParamSht = "[param$]"
strStnSht = "[stn$]"
strOutlierList = "[OL$]"

strSQLtest = "SELECT  s.Station_Abb, p.Parameter_Abb, db.Sample_Date, db.Concn, ol.Status" & _
                    " FROM ((" & strSourceSht & " AS db" & _
                    " INNER JOIN " & strStnSht & " AS s" & _
                        " ON db.Station_Name = s.Station_Name)" & _
                    " INNER JOIN " & strParamSht & " AS p" & _
                        " ON db.Parameter_Name = p.Parameter_Name) " & _
                    " LEFT JOIN " & strOutlierList & " AS ol" & _
                        " ON db.Concn = ol.Concn)


However I get this error "syntex error in FROM clause"
Help would be appreciated!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I see two opening parentheses and three closing parentheses. Perhaps that's the issue.
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,847
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top