Connect with SQL Database via ODBC by rStudio

--// Connect with SQL Database via ODBC
library(RODBC)


--// Open the source
channel <- odbcConnect("DATABASE_SERVER_NAME", uid="usr_studioR", pwd="XXXXXXX", believeNRows=FALSE)

--// Open the Record Set
Ex 01: dataframe <- sqlQuery(channel, "select iCompanyId, chCountryCode, vchCity from vCompany")


Ex 02: dataframe <- sqlQuery(channel, "select top 10 count(iCompanyId) as Total, chCountryCode as Country from vCompany group by chCountryCode  order by 1 desc")


--// Take a look at RS
dataframe