Can I use R to apply a for loop on a script in sql using a connection

Please, let me use this example to explain my question

schema=c(Analytics,Lato)
dbo_name=c(dbo1,dbo2)
Table_name=c(Data,prediction)

Tables are formed when we do.
sqlQuery(con,"SELECT * FROM Analytics.dbo1.Data") or sqlQuery(con,"SELECT * FROM Lato.dbo2.prediction")

Hence two tables will be formed. For my project, I have over 100 tables and doing "SELECT * for each would be eternity.

So I want to run a for loop in this way, but still didn't work.

for(i in 1:2){Table[i]= sqlQuery(con,"SELECT * FROM (schema[i].dbo_name[i].Table_name[i])")'

This still didn't work, please what am I getting wrong?

You need some additional technology like that provided by glue_sql for such a thing to work.

This resource may be of help too
https://db.rstudio.com/best-practices/run-queries-safely/

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.