Pass R Vector to Sql query
I'm using RODBC package to access my sql database in R. I haven't been able to find any useful information on how to pass a vector from R to sql as a vector. id <- ('00003', '00100') query <- sqlQuery(channel = channel, query = "select * from prod_cust_vw.store_dim where store_num in id") I would like to pass the id vector to sql rather than hard coding it. 1) sprintf Convert id into a string suitable for inclusion in the SQL statement and then insert it into the sql string using sprintf See ?sprintf . id <- c('00003', '00100') idString <- toString(sprintf("'%s'", id)) # "'00003', '00100'" sql