Skip to content
Prev 303542 / 398503 Next

Reference a variable inside a string and another for object assingments

I sometimes do this sort of thing with "tricks" like this:

  sql <- "select * from mytable where dt >= 'ADATE'"

  dbGetQuery( con, gsub('ADATE', '2012-06-12 23:14', sql) )



Or if mydates is a vector of dates stored as a POSIXt object:

for (id in mydates) {
 dbGetQuery( con,  gsub('ADATE', format(id), sql) )
}


-Don