sql - Pass R variable to RODBC's sqlQuery? -
is there way pass variable defined within r sqlquery function within rodbc package?
specifically, need pass such variable either scalar/table-valued function, stored procedure, and/or perhaps clause of select statement.
for example, let:
x <- 1 ## user-defined
then,
example <- sqlquery(mydb,"select * dbo.my_table_fn (x)")
or...
example2 <- sqlquery(mydb,"select * dbo.some_random_table foo foo.id = x")
or...
example3 <- sqlquery(mydb,"exec dbo.my_stored_proc (x)")
obviously, none of these work, i'm thinking there's enables sort of functionality.
build string intend pass. instead of
example <- sqlquery(mydb,"select * dbo.my_table_fn (x)")
do
example <- sqlquery(mydb, paste("select * dbo.my_table_fn (", x, ")", sep=""))
which fill in value of x
.
Comments
Post a Comment