This is a simple example using the RODBC package to return a query from a Microsoft SQL server to a data frame.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### 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