Hi
I have a table (HOC) containing the list of some items. I need to check another table (DA ) against HOC and sum up the occurrences of items and if no item is found then return 0 for sum.
My query:
This query does not show all the relevant items that exist in HOC; and give me the sum of only occurrences:
![Name: nullstuff.jpg
Views: 28
Size: 59.7 KB]()
How can I fix this? is this because of how I join them? Is it because of
and so if not both table contain the same item, then it won't show up in the result? but left join should be the correct method right?
Thanks in advance for your help.
I have a table (HOC) containing the list of some items. I need to check another table (DA ) against HOC and sum up the occurrences of items and if no item is found then return 0 for sum.
My query:
Code:
Select HOC.ListItemName,
Sum(Case When DA.Hierarchy IS not null then 1 else 0 End) As Total
--COALESCE(Sum(Case When DA.Hierarchy IS not null then 1 else 0 End) , 0) As Total
From DV_ListItems as HOC
Left join DV_CaseOverview AS DA
On HOC.ListItemName = Cast(DA.HierarchyOrder as varchar(2)) + ': ' + DA.Hierarchy
Join [DV_Data_NEW] As NG
ON NG.DEVIATION_NUMBER = DA.CaseID
Where
HOC.ListItemType = 'DV Hierarchy'
And ( Format(NG.[Completed_DATE],'yyyy-MM-dd') >= '2020-06-25' And Format(NG.[Completed_DATE],'yyyy-MM-dd') <= '2020-09-25')
Group by HOC.ListItemName
How can I fix this? is this because of how I join them? Is it because of
Code:
On HOC.ListItemName = Cast(DA.HierarchyOrder as varchar(2)) + ': ' + DA.Hierarchy
Thanks in advance for your help.