How do I get values for all months in T-SQL
I have a query that I would like to display all months for the year regardless if they have sales for that month or not. I know the issue is with the Group By, but how do I change the query so I don't need it? SELECT ISNULL(MONTH(sd.SBINDT),0) AS MonthSold, SUM(sd.SBQSHP) AS QtySold FROM dbo.SalesData sd WHERE sd.SBTYPE = 'O' AND sd.SBITEM = @Part AND YEAR(sd.SBINDT) = @Year AND sd.DefaultLocation = @Location GROUP BY MONTH(sd.SBINDT) Try this:- SELECT M.Months AS MonthSold,D.QtySold as QtySold FROM ( SELECT distinct(MONTH(sd.SBINDT))as Months from dbo.SalesData sd)M left join ( SELECT MONTH