I'm using RODBC to connect to a microsoft access database. Some queries work fine, but on one I keep getting the errors:
07002 -3010 [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
[RODBC] ERROR: Could not SQLExecDirect 'SELECT baseunit FROM archiverapp_common_units WHERE unitname = "ng/ml"'
I am using the 'sqlQuery' function to make the query. The SELECT statement given in the error is what I intend it to be and works when I copy-paste directly into Access. From what I've gathered looking at similar posts this frequently results from misspelling a column or table name, but everything seems correct here.
In R, there are two main ways to connect with Access databases: using the ODBC (Open DataBase Connectivity) facility available on many computers; and using the DBI (DataBase Interface) package in R. These notes deal with ODBC only.
There is a "Linked Table Manager" on the External Data tab of Access (at least the version I have). You would click this and select the tables you want to relink. Check the box for "Always prompt for new location". After clicking the OK button, you will be prompted for the new location.
Figured it out - apparently the answer was to use single quotes instead of double quotes in the WHERE clause. Changing the query string in my R code from this
'SELECT baseunit FROM archiverapp_common_units WHERE unitname = "ng/ml"'
to this
"SELECT baseunit FROM archiverapp_common_units WHERE unitname = 'ng/ml'"
solves the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With