I am trying to pass a list of stocks to a SQL query, sequentially. To do this, I pass a custom string to the sqlQuery command.
I build the string as follows:
my.stocks <- c('BIL','BTI')
a <- "SELECT TRADE_DATE_TIME,PRICE FROM MYDATA where TRADE_DATE_TIME > '2013-01-01' and INSTR_CODE = "
b <- my.stocks[1]
c <- "order by TRADE_DATE_TIME asc"
my.string <- paste(a,"'",b,"'",c)
my problem is that in the custom string, there are spaces between the quotation marks and variable b. How do I remove these spaces?
Use the
separgument topaste:You’ll also have to add a space at the start of the
cstring: