Pulling data using SQL and ADODB Error

JOCoyle

New Member
Joined
Sep 30, 2016
Messages
11
Hello,

Firstly I'm sorry if this is in the wrong thread but I wasn't sure which one to choose because the problem is to do with Excel, Access and SQL.

I am having a problem getting an SQL query to work at all.

The code for the SQL string is as follows:

Code:
   strSQL = "SELECT Staff_Roster.[User_ID], Staff_Roster.[Full_Name], Staff_Roster.[Zone], Staff_Roster.[Team], " & _
                    "Feedback_Scores_Advisor.[Score], Feedback_Data.[IssuesIdentified], Feedback_Data.[Issue], Feedback_Data.[Type] " & _
                "FROM Staff_Roster " & _
                    "INNER JOIN Feedback_Scores_Advisor " & _
                        "ON Staff_Roster.[User_ID] = Feedback_Scores_Advisor.[UserID] " & _
                    "INNER JOIN Feedback_Data " & _
                        "ON Staff_Roster.[User_ID] = Feedback_Data.[UserID] " & _
                    "WHERE Feedback_Scores_Advisor.[FirstDay] = " & FirstDay & " " & _
                        "AND Feedback_Data.[FDate] >= " & FirstDay & ";"

I'm not sure why it's not working but essentially it's giving me a Syntax Error (missing operator) in query expression error.

Hopefully the problem should be quite self-explanatory but if it doesn't make sense please ask and I will elaborate on the setup.

The relationships within the database tables are as follows (the ones appropriate to the problem):

  • Feedback_Data.UserID >---< Staff_Roster.User_ID
  • Feedback_Scores_Advisor.UserID >---< Staff_Roster.User_ID
  • (Both many to many)

Thank you in advance,

J Coyle.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Ok,

I found the problem..

Adding parenthesis from the from to the end of the first inner join like so works:

Code:
strSQL = "SELECT Staff_Roster.[User_ID], Staff_Roster.[Full_Name], Staff_Roster.[Zone], Staff_Roster.[Team], " & _
                    "Feedback_Scores_Advisor.[Score], Feedback_Data.[IssuesIdentified], Feedback_Data.[Issue], Feedback_Data.[Type] " & _
                "FROM (Staff_Roster " & _
                    "INNER JOIN Feedback_Scores_Advisor " & _
                        "ON Staff_Roster.[User_ID] = Feedback_Scores_Advisor.[UserID]) " & _
                    "INNER JOIN Feedback_Data " & _
                        "ON Staff_Roster.[User_ID] = Feedback_Data.[UserID] " & _
                    "WHERE Feedback_Scores_Advisor.[FirstDay] = " & FirstDay & " " & _
                        "AND Feedback_Data.[FDate] >= " & FirstDay & ";"

Hope this helps someone, somewhere..
J Coyle
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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