Basically I am trying to derive the WHERE part of a SELECT statement by unlisting
and paste
-ing a list where the list names represent the database TABLE Columns and the respective list values equal the parameters for the WHERE clause. Here is a simplified example ...
lst <- list(DATE=as.Date('2015-10-25'), NUM="0001", PROD="SOMETHING")
lst
$DATE
[1] "2015-10-25"
$NUM
[1] "0001"
$PROD
[1] "SOMETHING"
This would ideally be transformed into (the interesting bit starting in the second line after the WHERE
):
"SELECT SOME_COLUMNS WHERE
DATE = '", lst$DATE, "' AND
NUM = '", lst$NUM, "' AND
PROD = '" lst$PROD ,"'")
I am quite sure that someone knows of some fancy combination of apply()
,
paste(..,collapse ="' AND ")
and/or substitute()
that can accomplish that in an elegant form, but I am stuck.