I'm trying to execute a SQL query with dplyr on SQL Server:
tbl(con, sql(sqlQuery))
The query is generated dynamically using sprintf("SELECT ... WHERE a = '%s')
. This is a bad practice because it can be abused for SQL injection, but I can't find any documentation or working example for parameterized queries in dplyr. Can it be done, how?
The connection (con
) is using DBI, the odbc library, and the {SQL Server Native Client 11.0} ODBC driver:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "{SQL Server Native Client 11.0}",