Hello everyone, I have a problem. Can you help me, please?
I have connected R with SQL Server to import data from SQL Server into R by using Connection String to build predictive models. And, I need to export predicted data from R into SQL server. Can you help me with exporting data from Rstudio to SQL server, please?
Thank you very much.
Hello @TramDoan,
Did you try dbWriteTable
from package DBI
? It can help you. The doc from Rstudio about connection : https://db.rstudio.com/dbi/
1 Like
Since you already have imported data from SQL server I'm asumming you are familiar with SQL queries, so for a more flexible approach you can execute INSERT statements using DBI::dbSendStatement()
, take a look at this example.
rs <- dbSendStatement(
con,
"INSERT INTO cars (speed, dist) VALUES (?, ?)",
param = list(4L, 5L)
)
dbClearResult(rs)
Also, if you have multiple registers to insert and manually typing the sql statement would not be practical, you can use DBI::sqlAppendTable()
to programmatically prepare the sql command.
1 Like
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.