Pass R variable to RODBC's sqlQuery?

Is there any way to pass a variable defined within R to the sqlQuery function within the RODBC package? Specifically, I need to pass such a variable to either a scalar/table-valued function, a stored procedure, and/or perhaps the WHERE clause of a SELECT statement. For example, let:

x <- 1 ## user-defined


example <- sqlQuery(myDB,"SELECT * FROM dbo.my_table_fn (x)")


example2 <- sqlQuery(myDB,"SELECT * FROM dbo.some_random_table AS foo WHERE foo.ID = x")


example3 <- sqlQuery(myDB,"EXEC dbo.my_stored_proc (x)")

(You get the idea...)

Obviously, none of these work, but I'm thinking that there's something that enables this sort of functionality.

Any ideas?

Thanks in advance. Much appreciated!!


Build the string you intend to pass. So instead of

example <- sqlQuery(myDB,"SELECT * FROM dbo.my_table_fn (x)")


example <- sqlQuery(myDB, paste("SELECT * FROM dbo.my_table_fn (", 
                                x, ")", sep=""))

which will fill in the value of x.

Need Your Help

Can't get a function to work

python function

I am try to create a function that will end my game with a message counting down until it ends, and I am having to repeat this block of code a lot in my text adventure game, so I decided to make a

how can I debug exe with soem switch flags from command prompt

batch-file debugging command prompt

for e.g from command prompt I need to launch the exe with some switch flags under debugger. How do I do it?