library(RODBC)
con <- odbcDriverConnect("driver=SQL Server; server=name")
df <- data.frame(a=1:10, b=10:1, c=11:20)
Trying to upload the dataframe:
sqlSave(con, df, tablename='[MyDatabase].[MySchema].[MyTable]', rownames=F)
>Error in sqlColumns(channel, tablename) :
‘MyDatabase.MySchema.MyTable’: table not found on channel
..alternatively creating the table first and then appending to it:
cmd <- "create table [MyDatabase].[MySchema].[MyTable] ([a] int, [b] int, [c] int)"
sqlQuery(con, cmd)
sqlSave(con, df, tablename='[MyDatabase].[MySchema].[MyTable]', rownames=F, append=T)
>Error in sqlSave(con, df, tablename = "MyTable", rownames = F, :
42S01 2714 [Microsoft][ODBC SQL Server Driver][SQL Server]There is already an object named MyDatabase.MySchema.MyTable in the database.
[RODBC] ERROR: Could not SQLExecDirect 'CREATE TABLE MyDatabase.MySchema.MyTable ("a" int, "b" int, "c" int)'
What am I doing wrong?