Reading data from Microsoft SQL Server into R

Tried the RODBC package already?

http://cran.r-project.org/web/packages/RODBC/index.html

There's also the RJDBC package : http://www.rforge.net/RJDBC/

See also : http://www.r-bloggers.com/connecting-to-sql-server-from-r-using-rjdbc/


I've applied RODBC function suggested by other users. LinkSQL Server RODBC Connection

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

change two variables based on your Data table. 'server=mysqlhost;database=mydbname'


Niko, What operating system are you running? The answer to your question varies, depending on the platform you are using.

If you are using Windows (of any stripe), connecting to MSSQL Server via ODBC (RODBC) makes the most sense. When I connect to a MSSQL Server on Linux, I use JDBC as suggested by Joris. I would assume that JDBC is also the best solution for Macs, but I could very well be wrong.

Tags:

Sql Server

R