I am running this sql quer to get case counts by category per month. This displays a row if case count > 0 for any category for that month. What do I do for it to display a row even if case count = 0 for any category.
SELECT
CASE AA.DOS.SpecimenType.SpecimenTypeName WHEN 'Bone Marrow' THEN 'BM' WHEN 'Peripheral Blood' THEN 'PB' WHEN 'Leukemic Blood' THEN 'LB' WHEN
'Products of Conception' THEN 'POC' ELSE 'Tissue' END AS Spec,
((convert(varchar, (DateName(month,AA.ORDERS.Specimen.ReceivedDate)),1 ))+' '+(convert(varchar,year(AA.ORDERS.Specimen.ReceivedDate),1)))as Mdate,
Year(AA.ORDERS.Specimen.ReceivedDate) as yyear,
month(AA.ORDERS.Specimen.ReceivedDate)as mmonth,
CC.CytoStats.Case_Details.Cat1,
CC.CytoStats.Case_Details.Cat3,
COUNT (*) as CaseCount,
TotTab.CaseCount as total
FROM AA.ORDERS.ComponentOrder INNER JOIN
AA.ORDERS.ApCase INNER JOIN
AA.ORDERS.TestOrder ON AA.ORDERS.ApCase.CaseID = AA.ORDERS.TestOrder.CaseID INNER JOIN
AA.ORDERS.TestOrderSpecimen ON AA.ORDERS.TestOrder.TestOrderID = AA.ORDERS.TestOrderSpecimen.TestOrderID INNER JOIN
AA.ORDERS.Specimen ON AA.ORDERS.TestOrderSpecimen.SpecimenID = AA.ORDERS.Specimen.SpecimenID ON
AA.ORDERS.ComponentOrder.TestOrderID = AA.ORDERS.TestOrder.TestOrderID INNER JOIN
AA.DOS.SpecimenType ON AA.ORDERS.Specimen.SpecimenTypeID = AA.DOS.SpecimenType.SpecimenTypeID
Join CC.CytoStats.Case_Details on AA.ORDERS.ApCase.CaseNo = CC.CytoStats.Case_Details.CaseNo
join @CaseCounttable as TotTab on Year(AA.ORDERS.Specimen.ReceivedDate) = TotTab.yyear and Month(AA.ORDERS.Specimen.ReceivedDate) = TotTab.mmonth
WHERE AA.ORDERS.ComponentOrder.ComponentID = 100129
group by AA.DOS.SpecimenType.SpecimenTypeName,
AA.ORDERS.Specimen.ReceivedDate,
CC.CytoStats.Case_Details.Cat1,
CC.CytoStats.Case_Details.Cat3,
TotTab.caseCount
order by
Year(AA.ORDERS.Specimen.ReceivedDate) desc,
month(AA.ORDERS.Specimen.ReceivedDate)desc
SELECT
CASE AA.DOS.SpecimenType.SpecimenTypeName WHEN 'Bone Marrow' THEN 'BM' WHEN 'Peripheral Blood' THEN 'PB' WHEN 'Leukemic Blood' THEN 'LB' WHEN
'Products of Conception' THEN 'POC' ELSE 'Tissue' END AS Spec,
((convert(varchar, (DateName(month,AA.ORDERS.Specimen.ReceivedDate)),1 ))+' '+(convert(varchar,year(AA.ORDERS.Specimen.ReceivedDate),1)))as Mdate,
Year(AA.ORDERS.Specimen.ReceivedDate) as yyear,
month(AA.ORDERS.Specimen.ReceivedDate)as mmonth,
CC.CytoStats.Case_Details.Cat1,
CC.CytoStats.Case_Details.Cat3,
COUNT (*) as CaseCount,
TotTab.CaseCount as total
FROM AA.ORDERS.ComponentOrder INNER JOIN
AA.ORDERS.ApCase INNER JOIN
AA.ORDERS.TestOrder ON AA.ORDERS.ApCase.CaseID = AA.ORDERS.TestOrder.CaseID INNER JOIN
AA.ORDERS.TestOrderSpecimen ON AA.ORDERS.TestOrder.TestOrderID = AA.ORDERS.TestOrderSpecimen.TestOrderID INNER JOIN
AA.ORDERS.Specimen ON AA.ORDERS.TestOrderSpecimen.SpecimenID = AA.ORDERS.Specimen.SpecimenID ON
AA.ORDERS.ComponentOrder.TestOrderID = AA.ORDERS.TestOrder.TestOrderID INNER JOIN
AA.DOS.SpecimenType ON AA.ORDERS.Specimen.SpecimenTypeID = AA.DOS.SpecimenType.SpecimenTypeID
Join CC.CytoStats.Case_Details on AA.ORDERS.ApCase.CaseNo = CC.CytoStats.Case_Details.CaseNo
join @CaseCounttable as TotTab on Year(AA.ORDERS.Specimen.ReceivedDate) = TotTab.yyear and Month(AA.ORDERS.Specimen.ReceivedDate) = TotTab.mmonth
WHERE AA.ORDERS.ComponentOrder.ComponentID = 100129
group by AA.DOS.SpecimenType.SpecimenTypeName,
AA.ORDERS.Specimen.ReceivedDate,
CC.CytoStats.Case_Details.Cat1,
CC.CytoStats.Case_Details.Cat3,
TotTab.caseCount
order by
Year(AA.ORDERS.Specimen.ReceivedDate) desc,
month(AA.ORDERS.Specimen.ReceivedDate)desc