Exellent article, thank you.
For those of you that just hate creating views or would like to keep experimenting with different sql queries and have windows connection rather than a SQL ones, the following my help:
SQLconnection<-odbcDriverConnect("Driver=SQL Server; Server=MyDummyInstance\\BI_DEV; Database=AdventureWorksDW2012; trusted_connection=true;")
salesData<- sqlQuery(SQLconnection, "
select
sales.ProductKey,
p.ProductSubcategoryKey,
ps.EnglishProductSubcategoryName,
p.EnglishProductName,
sales.SalesTerritoryKey,
t.SalesTerritoryRegion,
sales.CustomerKey
from dbo.FactInternetSales as sales
inner join dbo.DimProduct as p on p.ProductKey = sales.ProductKey
inner join dbo.DimProductSubcategory as ps on ps.ProductSubcategoryKey = p.ProductSubcategoryKey
inner join dbo.DimSalesTerritory as t on t.SalesTerritoryKey = sales.SalesTerritoryKey;
")
odbcClose(SQLconnection)
The are some issues with the code (some missing parenthesis and some reference to data frame or variables that don't exist such as the product_contributions one).