Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is a simple example using the RODBC package to return a query from a Microsoft SQL server to a data frame.
##### This is a simple RODBC example
##### The ODBCDriverName will be the driver name in ODBC Administrator
require(RODBC)
#open the ODBC connection
ch <- odbcConnect("ODBCDriverName")
##### Alternative ODBC connection for Microsoft SQL Server
ch <- odbcDriverConnect(
"Driver=SQL Server; Server=servername\\instance; Database=databasename; UID=username; Pwd=password"
)
#run the query, store in a data frame
sqlResult <- sqlQuery(ch, "SELECT ...
FROM ...
WHERE ...
;")
#close the ODBC connection
odbcClose(ch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment