SqlUpdate returns the error "[RODBC] Failed exec in update" when updating a table read from DB

I create a table and write it to the database with RODBC. No problems.

First I tried to update the table in R and write the updates row by row using sqlUpdate in the same R script and the same R session as the initialization. No problems.

But when I try to break it into two scenarios (one for initializing the table and one for reading it in R, calculating updates and writing updates to the database), I get the following error (the work of importing and updating is fine, it just writes it back to DB that does not work):

[RODBC] Failed exec in Update

The code I use to update is the following (which worked when the table was in my R session, and the initialization and updates were in the same script):

conOut <- odbcConnect("myDB", uid = "myID", pwd = "myPwd", believeNRows = T)

sqlUpdate(conOut, myTable)

odbcClose(conOut)

- , , , ? - , , ?

.

+4
1

, :

sqlUpdate R sqlQuery , :

observedString <- paste("[Observed] = ", obs)
differenceString <- paste("[Difference] = ", myTable$Difference[n])
shapiroString <- paste("[pValueShapiroWilks] = ", myTable$pValueShapiroWilks[n])
...
clauseString <- paste0("rownames = '", myTable$rownames[n], "'")    

updateString <- paste0("UPDATE [myDB].[dbo].[myTable]
   SET ", 
  observedString, ", ", 
  differenceString, ", ",
  shapiroString, ", ",
  ljungBoxString, ", ",
  adfString, ", ", 
  warningString, ", ", 
  changeString, 
 " WHERE " , clauseString)

conOut <- odbcConnect("myDB", uid = "myID", pwd = "myPwd", believeNRows = T)

sqlQuery(conOut, updateString)

.

, sqlUpdate ...

0

All Articles