我有一个功能
testFun <- function(myTeam){
print(myTeam)
teamResults <- sqlQuery(channel,paste(
"
SELECT soccer.tblResultsallMore.TEAMNAME,
sum(case when soccer.tblResultsallMore.RES='W' then 1 else 0 end) as W,
sum(case when soccer.tblResultsallMore.RES='L' then 1 else 0 end) as L,
sum(case when soccer.tblResultsallMore.RES='D' then 1 else 0 end) as D
FROM soccer.tblResultsallMore
WHERE soccer.tblResultsallMore.TEAMNAME=myTeam
GROUP BY soccer.tblResultsallMore.TEAMNAME
"))
return(teamResults) # no error if this is not returned
}
testFun("Everton")
如果我在代码中硬编码“埃弗顿”,我会得到所需的输出
[1] "Everton"
TEAMNAME W L D
1 Everton 1734 1463 1057
但是参数有错误
[1] "Everton"
[1] "42S22 207 [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'myTeam'."
[2] "[RODBC] ERROR: Could not SQLExecDirect
非常感谢帮助