【发布时间】:2011-11-14 20:34:51
【问题描述】:
我正在学习 R,向 SAS 挥手告别,我还是新手,不知何故我很难找到我正在寻找的东西。
但是对于这个特定的案例,我读到: Pass R variable to RODBC's sqlQuery? 并让它为我自己工作,只要我只在目标表中插入一个变量。
这是我的代码:
library(RODBC)
channel <- odbcConnect("test")
b <- sqlQuery(channel,
"select top 1 Noinscr
FROM table
where PrixVente > 100
order by datevente desc")
sqlQuery(channel,
paste("insert into TestTable (UniqueID) Values (",b,")", sep = "")
当我将 top 1 替换为任何其他数字(假设为 top 2)并运行完全相同的代码时,我收到以下错误:
[1] "42000 195 [Microsoft][SQL Server Native Client 10.0][SQL Server]
'c' is not a recognized built-in function name."
[2] "[RODBC] ERROR: Could not SQLExecDirect
'insert into TestTable (UniqueID) Values (c(8535735, 8449336))'"
我知道这是因为生成了一个额外的 c,我在给出命令时假设为列:paste(b)。
那么在使用paste(b) 时,我怎样才能得到"8535735, 8449336" 而不是"c(8535735, 8449336)"?还是有其他方法可以做到这一点?
【问题讨论】:
标签: r