0

I am using this code to connect

library(dplyr) library(DBI) con <- dbConnect(odbc::odbc(), "SQLSERVERR") # Can't use this con1 <- dbConnect(odbc::odbc(), "SQLSERVERR",database = "db1") con2 <- dbConnect(odbc::odbc(), "SQLSERVERR",database = "db2") tbx <- tbl(con1,"some_table") 

But my connection has tables inside databases and I would like to send sql queries to them using dplyr.

something like

tbx <- tbl(con, db = "db1", "some_table") 

Thanks for the help.

1
  • This is very broad, and seems like you're looking more for a tutorial than help with a specific code question. There is pretty extensive guidance I'd recommend starting with on databases with dplyr Commented Jul 11, 2019 at 15:43

1 Answer 1

0

It might depend on a few things. I had the best luck doing a similar task using the RODBC package. SQL Server RODBC Connection I could access views within the database this way using the sqlFetch function but it is possible to do the query within the sqlQuery function as shown in the example. If you're accessing a secure, live database, you may want to try the odbcConnect function (also within the same package), having added it as a datasource (https://turbofuture.com/computers/Connect-to-SQL-Server-from-R).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.