Are you looking for this?
sql <- paste0("select *
FROM GRID Z
where Z.LAT ='", Xlat,"' AND Z.LON = '", Xlon,"'")
I assumed that your variables are character. In case the above is running behind a web server, there are options for URL encode and escape to avoid code injections... like this
EDIT: About this:
I would also like to know if instead of = is there something to match the closest or nearest values.
Since you are executing your query via a SQL engine that is more a SQL question than a R one. Like @Vivek says you can do that in sqldf
but I guess your data are in a remote database, so it wouldn't help in this case.
All SQL flavours have like
, so just use it in your query. Please tell me if I'm misunderstanding your question.
sql <- paste0("select *
FROM GRID Z
where Z.LAT like '", Xlat,"' AND Z.LON like '", Xlon,"'")