I have a view (vMonthlyBalSheet) that totals user activity by month
SELECT UserID, DATEPART(yy, ActivityDate) AS ActivityDateYear, DATENAME(m, ActivityDate) AS ActivityDateMonth,
COUNT(*) AS DaysWorked, SUM(Offage) AS NetCashVar, SUM(UnitsSold) AS TotalSold
FROM vBalanceSheet
GROUP BY UserID, DATEPART(yy, ActivityDate), DATENAME(m, ActivityDate)
However, this view will not return rows for months where a user has no activity. I need a way to return rows for months where there was no activity.
I have tried taking this view and joining it with a table that contains records for all months and years.
What I need is 12 rows for each user in the database (the last 12 months) whether they had activity or not.
SELECT UserID, DATEPART(yy, ActivityDate) AS ActivityDateYear, DATENAME(m, ActivityDate) AS ActivityDateMonth,
COUNT(*) AS DaysWorked, SUM(Offage) AS NetCashVar, SUM(UnitsSold) AS TotalSold
FROM vBalanceSheet
GROUP BY UserID, DATEPART(yy, ActivityDate), DATENAME(m, ActivityDate)
However, this view will not return rows for months where a user has no activity. I need a way to return rows for months where there was no activity.
I have tried taking this view and joining it with a table that contains records for all months and years.
What I need is 12 rows for each user in the database (the last 12 months) whether they had activity or not.