How to Insert a Dataframe into a SQL Server Table

How to insert a dataframe into a SQL Server table?

[edited] Perhaps pasting the names(df) would solve the scaling problem:

   values <- paste( " df[  , c(", 
paste( names(df),collapse=",") ,
")] ", collapse="" )
values
#[1] " df[ , c( a,b,c )] "

You say your code is "working".. I would also have thought one would use sqlSave rather than sqlQuery if one wanted to "upload".

I would have guessed this would be more likely to do what you described:

 sqlSave(con, df, tablename = "MyTable")

Error while trying to insert Python dataframe into SQL table

I simply included the function to replace NaN with 0 and it now loads all rows successfully using the following line of code right after I create the dataframe I want to load (df)

df = df.fillna(value=0)

Insert R DataFrame into SQL Server Table

Please follow the TIBCO community solution suggested here: https://community.tibco.com/wiki/tibcor-enterprise-runtime-r-fast-writeback-sql-server-2016

In your case it would be something like below:

dbcon <- RODBC::odbcDriverConnect(connection_string )
RODBC::sqlSave(dbcon, dat = dataf, "SQlServerTableDestinationName")

Please let me know if it helps



Related Topics



Leave a reply



Submit