sqlQuery给出错误

时间:2017-11-06 10:55:54

标签: sql r

当我尝试在R中运行以下查询时它不起作用而在sql中使用相同的查询

Vol_Traded <- sqlQuery(dbConnect, paste('select BusinessDate,sum(sales)sales from data
where A.BusinessDate >= '2016-02-05' and ID = 533177 
and DATENAME(dw, BusinessDate) NOT IN ('Saturday', 'Sunday')
group by BusinessDate
order by BusinessDate'))

我在输出中得到的错误是:

  

“[RODBC]错误:无法SQLExecDirect”

1 个答案:

答案 0 :(得分:0)

在R中使用双引号作为字符串吗?

Vol_Traded <- sqlQuery(dbConnect, paste("select BusinessDate, sum(sales) as sales from data
where A.BusinessDate >= '2016-02-05' and ID = 533177 
and DATENAME(dw, BusinessDate) NOT IN ('Saturday', 'Sunday')
group by BusinessDate
order by BusinessDate"))

我的猜测是唯一的问题是引号问题。