Search code examples
sqlrrstudiorodbc

How can i do a query with SQLsave in R?


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


Solution

  • 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)