我一直在尝试将SQL服务器从多个数据库链接到R,但我收到以下错误
42000 156 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'as'.
42000 102 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'B'.
42000 102 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'C'.
[RODBC] ERROR: Could not SQLExecDirect
我正在尝试以下查询
dbConnect <- odbcDriverConnect('driver={SQL Server};server=server1;database=MarketData;database=BusinessData;trusted_connection=true')
Daily_Date <- sqlQuery(dbConnect,paste('select A.BusinessDate, MAX(B.RecordDate) as LastDividendDate,
+ MIN(C.RecordDate) as NextDividendDate from
+ (select BusinessDate, SUM(Quantity) QOL
+ from BusinessData..TradeData
+ where ID = 1729903 and BusinessDate >= as.Date("2016-02-24")
+ group by BusinessDate) A
+ left outer join
+ (SELECT RecordDate
+ FROM MarketData..DivData
+ where ID = 1729903) B
+ on A.BusinessDate >= B.RecordDate
+ left outer join
+ (select RecordDate from MarketData..DivData
+ where InstrumentID = 1729903) C
+ on A.BusinessDate <= C.RecordDate
+ group by A.BusinessDate
+ order by A.BusinessDate'))
相同的查询在SQL服务器中工作但在R中不起作用 有什么建议吗?