0
我有一個查詢特定股票交易數據的sql查詢。我正試圖通過不同的股票來應用特定的分析。下面的代碼顯示了我試圖將循環中的查詢以及「硬編碼」查詢傳遞給變量。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)
}
看一看'paste'? – sgibb