I'm using dplyr (0.7.0)
, dbplyr (1.0.0)
, DBI 0.6-1
, and odbc (1.0.1.9000)
. I would like to do something like the following:
db1 <- DBI::dbConnect(
odbc::odbc(),
Driver = "SQL Server",
Server = "MyServer",
Database = "DB1"
)
db2 <- DBI::dbConnect(
odbc::odbc(),
Driver = "SQL Server",
Server = "MyServer",
Database = "DB2"
)
x <- tbl(db1, "Table1") %>%
dplyr::left_join(tbl(db2, "Table2"), by = "JoinColumn")
but I keep getting an error that doesn't really seem to have any substance to it. When I use show_query
it seems like the code is trying to create a SQL query that joins the two tables without taking the separate databases into account. Per the documentation for dplyr::left_join
I've also tried:
x <- tbl(db1, "Table1") %>%
dplyr::left_join(tbl(db2, "Table2"), by = "JoinColumn", copy = TRUE)
But there is no change in the output or error message. Is there a different way to join tables from separate databases on the same server?