Important Notice !!!

This blog has been discarded and no update any more.

Please visit http://www.quantlego.com for active updates.

Sorry for any inconvenience.





Sunday, July 14, 2013

Import data from Microsoft SQL server to R using RODBC package

| |
As preparation, first create an ODBC driver connection for SQL Server by
Control Panel >> Administrative Tools >> Data Sources (ODBC)


Then import data from SQL server with following R code
library(RODBC)
conn <- odbcConnect(dsn="ACCPAC 54 SQL",uid="my_ID",pwd="my_PWD")
#sqlTables(channel)
queryResult <- sqlQuery(conn, "SELECT * FROM TableName")
odbcClose(conn)
dim(queryResult)
Alternatively, without creating ODBC driver connection, you can use following R code to directly set up connection
library(RODBC)
conn <- odbcDriverConnect("Driver=SQL Server; Server=xxx.xx.xxx.xx; Database=test_DB; Uid=my_ID; Pwd=my_PWD;")
#sqlTables(channel)
queryResult <- sqlQuery(conn, "SELECT * FROM TableName")
odbcClose(conn)
dim(queryResult)

0 comments:

Post a Comment

Powered by Blogger.