I have an SQL script which I need to run using R Studio. However, my SQL script has one variable that is defined in my R environment. I am using dbGetQuery; however, I do not know (and I didn't find a solution) how to pass these variables.
library(readr)
library(DBI)
library(odbc)
library(RODBC)
#create conection (fake one here)
con <- odbcConnect(...)
dt = Sys.Date()
df = dbGetQuery(.con, statement = read_file('Query.sql'))
The file 'Query.sql' makes reference to dt. How do I make the file recognize my variable dt?
glue_sql: glue.tidyverse.org/reference/glue_sql.html.conand use.con(dot), probably a typo. (2) You appear to be usingconcreated fromRODBCbut trying to use it in aDBIfunction. I have not usedRODBC, but are you certain that is appropriate and functional? (3) In reality, you needRODBC(withodbcConnectandsqlQuerybut no bound parameter support), or you needDBIandodbc(withdbConnectanddbGetQuery, with bound parameter support). You do not need both.