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
Find All Unique Values in Column Separated by Comma
Merging More Than 2 Dataframes in R by Rownames
Changing Binary Variables to Yes/No
Formatting a Date in R Without Leading Zeros
Getting All Combinations Which Sum Up to 100 Using R
How to Install Roracle Package on Windows 7
Delete Entries with Only One Observation in a Group
Aggregate 1-Minute Data into 5-Minute Average Data
Ggplot2 for Grayscale Printouts
The Condition Has Length ≫ 1 and Only the First Element Will Be Used
How to Align Multiple Ggplot2 Plots and Add Shadows Over All of Them