我有一个 sql 查询,它可以获取特定股票的交易数据。我现在正在尝试遍历不同的股票以应用特定分析。下面的代码显示了我尝试将变量传递给循环中的查询以及“硬编码”查询。
任何指导将不胜感激。
my.stocks <- c('ABL','IPL')
for (i in 1:2)
{
channel <- odbcConnect("Public_Trades")
my.frame1 <- sqlQuery(channel,
"SELECT TRADE_DATE_TIME,
PRICE,
QUANTITY
FROM [ISLDWODS].[HERMES_PUBLIC].[PUBLIC_TRADES_HISTORY]
where TRADE_DATE_TIME > '2012-11-01' and TRADE_TYPE ='AT' and INSTR_CODE = " & my.stocks[i] &
"order by TRADE_DATE_TIME asc")
my.frame2 <- sqlQuery(channel,
"SELECT TRADE_DATE_TIME,
PRICE,
QUANTITY
FROM [ISLDWODS].[HERMES_PUBLIC].[PUBLIC_TRADES_HISTORY]
where TRADE_DATE_TIME > '2012-11-01' and TRADE_TYPE in ('AT','UT') and INSTR_CODE = 'MPC'
order by TRADE_DATE_TIME asc")
close(channel)
}