Reading data from Microsoft SQL Server into R

Viewed 44692

Is it possible to read the data stored in MS SQL server from R interface?

If it is I would be also thankful if anyone could show the way to do it.

7 Answers

You can connect to SQL server using DBI package, which I think works better than RODBC. DBI is a database interface package for relational databases. for SQL I use it along with odbc package as in the example below.

Visit this page for full details: Database Queries with R

An example would be as follows

library(DBI) library(odbc) con <- dbConnect(odbc::odbc(), .connection_string = "driver={SQL Server}; server= ServerName; database=DatabaseName; trusted_conncetion=true")) dbGetQuery(con,'Select * from Table')

library("RODBC")

dbhandle <- odbcDriverConnect('driver={SQL Server};server=;database=;trusted_connection=true')

currTableSQL<-paste("SELECT * FROM ",sep="")

currTableDF<-sqlQuery(dbhandle,currTableSQL)

Related