Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Too few parameters" trying to connect to a Microsoft Access database in R

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.

like image 766
JaredL Avatar asked Jul 25 '14 20:07

JaredL


People also ask

How do I connect to an Access DataBase in R?

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.

How do I change the path in Access?

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.


1 Answers

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.

like image 182
JaredL Avatar answered Sep 23 '22 13:09

JaredL