You can create a table variable or a temporary table holding all the months and then do a LEFT OUTER JOIN with this table
DECLARE@tblCalendar TABLE
(
Month_NameVARCHAR(20),
Month_NumTINYINT,
Year_NumSMALLINT
)
INSERT@tblCalendar
SELECT'January', 1, 2013 UNION ALL
SELECT'February', 2, 2013 UNION ALL
SELECT'March', 3, 2013 UNION ALL
SELECT'April', 4, 2013 UNION ALL
SELECT'May', 5, 2013 UNION ALL
SELECT'June', 6, 2013 UNION ALL
SELECT'July', 7, 2013 UNION ALL
SELECT'August', 8, 2013 UNION ALL
SELECT'September', 9, 2013 UNION ALL
SELECT'October', 10, 2013 UNION ALL
SELECT'November', 11, 2013 UNION ALL
SELECT'December', 12, 2013
SELECTCOUNT(1) AS Total, tc.Month_Name AS [Month Name], tc.Month_Num AS [Month], tc.Year_Num AS [Year]
FROM@tblCalendar AS tc
LEFT OUTER JOIN (
select count (*) as 'Total', datename (mm, date_time) as 'Month Name',MONTH (date_time) as 'Month' ,Year (date_time) as 'Year'
from opencall
left join updatedb
on updatedb.callref = opencall.callref
where
(updatetxt like 'Call assigned to the WIBS group%')
and year(date_time) in ('2013')
and priority not in ('UNIX')
and probcode like ('CL%')
group by datename (mm, date_time), Year (date_time), MONTH (date_time)
) AS C
ONtc.Month_Name = C.[Month Name]
ANDtc.Month_Num = C.[Month]
ANDtc.Year_Num = C.[Year]
ORDER BY Year_Num, Month_Num
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/