0

I can't pass my variable Q1 in a SQL query in R: code:

Q1=23
sqlStatement <- paste("SELECT long,lat FROM "Interpolation" where var1>",Q1,'"',sep=""))

inter1<-dbGetQuery(con, sqlStatement;)

Erreur:

Error: unexpected symbol in "sqlStatement <- paste("SELECT long,lat FROM "Interpolation"

Can someone help me please !

Ps:I tried a lot of suggestions that I found on the forum but nothing works -How to use a variable name in a SQL statement? -Pass R variable to a sql statement

Community
  • 1
  • 1
user26480
  • 367
  • 2
  • 5
  • 15

1 Answers1

1

Try this one

paste("SELECT long,lat FROM 'Interpolation' where var1>",Q1,sep="")

or

paste("SELECT long,lat FROM Interpolation where var1>",Q1,sep="")
gd047
  • 29,749
  • 18
  • 107
  • 146
  • @ George Dontas :Thanks a lot for the help it works, there was also a confused between " and ' -----> sqlStatement <- paste('SELECT long,lat FROM "Interpolation" where var1>',Q1,sep="") – user26480 Oct 20 '14 at 14:28
  • @♦George Dontas :if they are two conditions Q1 et Q2 , what is the syntax? – user26480 Oct 26 '14 at 19:05
  • paste("SELECT long,lat FROM Interpolation where var1>",Q1," and var2>",Q2,sep="") – gd047 Oct 27 '14 at 11:19