The following code uses CTE (Common Table Expression). Can someone help me rewrite the code without CTE.
Basically, I would like the same result but without using CTEs.
; WITH TallyTable_CTE AS ( SELECT ROW_NUMBER() OVER (ORDER BY StockCode) AS ID FROM Data.Stock ) ,LastDayOfMonth_CTE AS ( SELECT EOMONTH(DATEFROMPARTS(2016, ID, 1)) AS LastDayDate FROM TallyTable_CTE WHERE ID <= 12 ) SELECT CTE.LastDayDate ,SUM(SLS.SalePrice) AS TotalDailySales FROM Data.SalesByCountry SLS INNER JOIN LastDayOfMonth_CTE CTE ON CTE.LastDayDate = CAST(SLS.SaleDate AS DATE) GROUP BY CTE.LastDayDate ORDER BY CTE.LastDayDate
Please let me know if you need anything from me to assist you in finding a solution