top of page
Search

Connecting SQL in R

  • Writer: Lila Guimarães Reis
    Lila Guimarães Reis
  • Aug 28, 2021
  • 1 min read

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)




 
 
 

Comentarios


Post: Blog2 Post
bottom of page