Skip to content
Prev 280270 / 398506 Next

SQL> select ... where "R variable"

On Wed, Dec 14, 2011 at 7:04 AM, agent dunham <crosspide at hotmail.com> wrote:
Since you have changed the problem by introducing new elements into it
clearly the answer must change too.  Either:

1. write R_variable to a table in your database and revise your SQL
statement so that its valid SQL or
2. if there are only a few elements in R_variable$x e.g. making it a
plain vector with R_variable <- 1:10 then construct the appropriate
sql statement:

R_variable <- 1:10
sql_stmt <- sprintf("select v1
   from sqltable
   where v2 in ( %s )
   order by v2
", toString(R_variable))

which gives:
select v1
   from sql_table
   where v2 in ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )
   order by v2