I am trying to run a MySQL query using RMySQL which includes a LIKE
and a custom variable inside the query.
Here is an example of my query
customvar= 'some text'
(simpleQuery<-paste("SELECT * FROM `table` WHERE NameOfField like '%",customvar,"%'"))
res<-dbGetQuery(con, simpleQuery)
The thing is that for some reason simpleQuery interprets the query like this
[1] "SELECT * FROM `table` WHERE NameOfField '% some text %'"
Note the spaces before and after some text
those are preventing my query to get proper results
I have no idea why those spaces are being generated. I tested my query without those spaces and it does give back results, so I am sure that those spaces are making my query fail.
Any idea of a way around this issue?
Versions: R 2.14.0 / RMySQL 0.8
Thanks in advance
The default in
paste
issep=' '
(space), but you probably intendedsep=''
(empty string). In recent R you can usepaste0
instead.