您好我正在尝试将日期粘贴到R中的SQL查询中。我的代码如下:
Date1<-'20171031'
Date2<-'20170731'
SQLCommand<- data.frame(sqlQuery(myConn, "SELECT fc.[FactSet Fund Code], fc.FactsetDate, fc.[Asset Class], fc.[Fund Manager], d.Id AS DeskID, d.[Name] AS DeskName, c.ClosingDate, m.NumericGrossPerformanceTarget, fc.[% Factor Risk], fc.[Predicted Tracking Error], fc.[Portfolio Predicted Beta]
FROM [PortfolioAnalytics].[Data_Factset].[FundChar] fc
LEFT OUTER JOIN Data_Axioma.FactSetAccount fsa ON fc.FactsetAccountCode = REPLACE(fsa.Code, '_', '')
LEFT OUTER JOIN dbo.Portfolio p ON fsa.PortfolioId = p.Id
LEFT OUTER JOIN dbo.Mandate m ON p.UnderlyingId = m.id
INNER JOIN dbo.Mandate c ON p.UnderlyingId = c.id
LEFT OUTER JOIN dbo.Desk d ON m.DeskId = d.Id
WHERE IncludesCash = 1
AND [FactSet Fund Code] IS NOT NULL
AND [Fund Manager] IS NOT NULL
AND [Asset Class] IS NOT NULL
AND FactsetDate IN ("Date1, Date2")
ORDER BY [Predicted Tracking Error] DESC"))
我收到意外的符号错误。
答案 0 :(得分:1)
使用字符串操作
执行此操作Date1 <- "20171031"
Date2 <- "20170731"
query <- sprintf("select * from yourtable
where column between '%s' and '%s'", Date1, Date2)