I have a query that pulls the Sales by Customer by Fiscal Month. However, I have some Customers that did not make purchases in a given month. For those situations, I would like the MonthNum field to have a 0 for the SalesDlr value, but the MonthNum value still needs to be the actual Month Number. Currently, I do not get a MonthNum value in the query below:
SELECT
a.Customer,
a.CustomerName,
a.MonthNum,
a.FiscalYear,
a.SalesDlr
FROM
(SELECT
sd.SBCUST AS Customer,
sd.RMNAME AS CustomerName,
fc.FiscalMonthNum AS MonthNum,
fc.FiscalYear,
SUM(sd.SBEPRC) AS SalesDlr
FROM
dbo.SalesData sd
LEFT OUTER JOIN dbo.FiscalCalendar fc ON fc.FiscalDate = sd.SBINDT
WHERE
sd.SBTYPE = 'O'
AND
sd.SBINDT > '2012-12-31'
AND
sd.SBCLS NOT IN ('1500')
GROUP BY
sd.SBCUST,
sd.RMNAME,
fc.FiscalMonthNum,
fc.FiscalYear
)a
GROUP BY
a.Customer,
a.CustomerName,
a.MonthNum,
a.FiscalYear,
a.SalesDlr
ORDER BY
a.Customer,
a.MonthNum,
a.FiscalYear
How can I fix that?