top of page
Search

Connecting SQL in R

Writer's picture: Lila Guimarães ReisLila Guimarães Reis

Updated: Aug 28, 2021



Package : RODBC


  • installing package

install.packages("RODBC")


library(RODBC)


  • Connection

myConn <- odbcConnect("ODBC_SQLServer")


  • Running SQL in R


res <- sqlQuery(myConn, "SELECT *

FROM TSOM_MSSQL.dbo.Customers")

res



res2 <- sqlQuery(myConn,"

select

CustomerName as 'Name',

PricePerItem as Price,

avg(PricePerItem) over (partition by CustomerName) as 'Customer Mean'

from TSOM_MSSQL.dbo.orders3")

View(res2)




12 views0 comments

Recent Posts

See All

Comments


Post: Blog2 Post
bottom of page