1

I am trying to insert a dataframe into a sql table. The sqlUpdate code gives a inherits(channel, "RODBC") channel is missing error Insertdata<-sqlUpdate(DBcon, df, tablename = "DataQuality", sqlColumns(special=FALSE)) My second attempt was this

Insertdata<-sqlQuery(DBcon,paste("insert into DataQuality", df, sep = ""))

sqlQuery shows an error of

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'Nothing to add'

." (this is the first column and row of data)

"[RODBC] ERROR: Could not SQLExecDirect 'insert into DataQuality(Descriptions,Date,Name,Ref)SELECT Descriptions,Date,Name,Ref FROMc(\"Nothing to add\"

, and seems to stop at the end of the first column.

5
  • 1
    Did you try to use sqlSave? Per the docs: sqlSave saves the data frame dat in the table tablename. If the table exists and has the appro- priate structure it is used, or else it is created anew. Commented May 18, 2017 at 14:28
  • I thought sqlSave was for creating a new table I am not sure how I would use this to insert into a table? when I try Insertdata<-sqlSave( DBcon, df, "DataQuality") I get the error saying the table already exists. Commented May 18, 2017 at 15:03
  • Use the append=True argument. Commented May 18, 2017 at 15:12
  • I tried using append=TRUE but it crashes R. I have seen this post onSqlSave. Commented May 18, 2017 at 15:58
  • I managed to find out why, I needed rownames=FALSE. my final code that worked was Insertdata<-sqlSave( DBcon, df, "DataQuality",rownames=FALSE, append=TRUE)Thank you for the help. Commented May 18, 2017 at 16:08

1 Answer 1

1

Insertdata<-sqlSave( DBcon, df, "DataQuality",rownames=FALSE, append=TRUE) This will update the SQL table with the new dataframe.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.