-1

I have a question about SqlSave ,

I Know that sqlsave Writes a Data Frame to a Table in an ODBC Database , but i would like to write an insert query.

How can i do that with Sqlsave ,can u give me an example ?

Thank you

foboss
  • 430
  • 4
  • 14
  • sqlSave cannot work with query... If you already have your query then why don't you use sqlQuery function? – vrajs5 May 29 '14 at 07:03
  • @vrajs5 this is the point ,sqlQuery works but it does not scale very well, i have to insert a lot of values but it insert only the first row, to resolve that i did a loop still it's not working as i expected – foboss May 29 '14 at 07:13

2 Answers2

2

Your question already answered => How to insert a dataframe into a SQL Server table?

Read RODBC manual http://cran.r-project.org/web/packages/RODBC/index.html

Community
  • 1
  • 1
rischan
  • 1,553
  • 13
  • 19
0

If the structure of your my_df data.frame is equal to the table my_table in a data base (same column names and formats) the next query will insert new data to it:

con <- odbcConnect("my_dsn", uid = "my_uid", pwd = "my_pwd")

sqlSave(con, my_newdf, tablename = "my_table", 
        append = TRUE, rownames = FALSE, colnames = FALSE)
Andriy T.
  • 2,020
  • 12
  • 23