Extract and include SQL data with R

0

I'm designing a database in SQL that will have tables that store collected data and a table that stores calculated indexes of that data for later display on a dashboard. I want to calculate these indexes with the language R. I would like to know two things:
1 - How do I pull data from my SQL data tables to R so I can do the calculations?
2 - How do I store the results of my calculations in the R in my SQL index table?

    
asked by anonymous 31.07.2017 / 14:19

1 answer

3

You use the RODBC package, then just ask:

#testa se vc tem o pacote, caso não instala    
list.of.packages <- c("RODBC") 
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)   

library(RODBC)
dbhandle <- odbcDriverConnect('driver={SQL Server};server=mysqlhost;database=mydbname;trusted_connection=true')
res <- sqlQuery(dbhandle, 'select * from information_schema.tables')
    
08.08.2017 / 07:53