Run multiple update queries on R

Viewed 25

Im currently learning how to use rstudio, and its rodbc package.

I've been working on a script that changes certain values for names. But I cant seem to get it to run all the lines and change the whole file in a single query. I've tried using "+" and "%>%", but I guess sql doesnt recognize that synthax.

library(RODBC)
library(odbc)
library(dplyr)


## Access file conection
diag<- "bases de prueba/DIAGNOSTICO 22.MDB"
con <- RODBC::odbcConnectAccess2007(diag)


tabla<-sqlFetch(con,'tres', rownames=FALSE)

##I'd like to run these (and more instructions like this ones), in a single run.
updatequery <- paste("update tres set centro = '" ,"Centro 1", "' where centro = '1'")
               paste("update tres set centro = '" ,"Centro 2", "' where centro = '2'")
               paste("update tres set centro = '" ,"IREMI", "' where centro = '3'")

##Apply changes on to access file.
RODBC::sqlQuery(con,updatequery)

Im just a beginner so any advice or tip will be usefull! Thanks for your time.

0 Answers
Related