使用粘贴函数将R数据帧放入sql可用列表
我在RRdataframe中有一个dataframe/列表,我想直接在RODBC查询中使用它,比如使用粘贴函数将R数据帧放入sql可用列表,r,printf,rodbc,sqldf,R,Printf,Rodbc,Sqldf,我在RRdataframe中有一个dataframe/列表,我想直接在RODBC查询中使用它,比如 Rdataframe= c('123456','234561','678912') a= sqlQuery(connection, "Select * from table A where A.Id in Rdataframe") 查询必须是这样的,也就是说,我不能先在R中提取表,然后再进行查找 因此,我认为它只能在以下格式中运行 a= sqlQuery(connection, "Sele
Rdataframe= c('123456','234561','678912')
a= sqlQuery(connection, "Select * from table A where A.Id in Rdataframe")
查询必须是这样的,也就是说,我不能先在R中提取表,然后再进行查找
因此,我认为它只能在以下格式中运行
a= sqlQuery(connection, "Select * from table A where A.Id in ('123456','234561','678912'))
但是,尽管sprintf&paste做了几次尝试,我还是没有成功
这是我试图尝试的,但失败了
attempt1= sqlQuery(connection, sprintf("Select * from table A where A.Id in %s", Rdataframe))
attempt2=paste(Rdataframe, sep=",")
然后在查询中使用这个trument2结构
每一个帮助都很重要
Rdataframe= c('123456' , '234561' , '678912')
df_str = paste(Rdataframe , collapse = "','" , sep=" ")
queryStr = paste("Select * from table A where A.Id in ('" ,df_str , "')" , sep="")
print(queryStr)
给出输出
[1] 从表A中选择*,其中A.Id位于“123456”、“234561”和“678912”中
你能把你的尝试产生的字符串贴出来吗?