For some reason, I have what should be a simple query giving me some serious fits.
Using example table #Steps as follows
Is there a way I could pull a list of each Item, Each Step, and a count of how many are in each, but including missing steps with a 0?
ie..
Returns
This gives me the counts I need, but without the missing items (Review step 3 count 0). Is there a way I could query this to return a row for each Step?
I tried to create a temp table that just had the possible list of steps (1-4 in this example) and joining to it, but couldn't get it to work right.
Using example table #Steps as follows
Code:
Item Step
Review 1
Review 2
Review 4
YearEnd 1
YearEnd 3
YearEnd 4
Is there a way I could pull a list of each Item, Each Step, and a count of how many are in each, but including missing steps with a 0?
ie..
Code:
SELECT Item, s.Step, COUNT(s.Step) [Count]
FROM #Steps s
GROUP BY Item, s.Step
ORDER BY Item
Code:
Item Step Count
Review 1 2
Review 2 1
Review 4 1
YearEnd 1 2
YearEnd 3 1
YearEnd 4 1
This gives me the counts I need, but without the missing items (Review step 3 count 0). Is there a way I could query this to return a row for each Step?
Code:
Item Step Count
Review 1 2
Review 2 1
Review 3 0
Review 4 1
YearEnd 1 2
YearEnd 2 0
YearEnd 3 1
YearEnd 4 1
I tried to create a temp table that just had the possible list of steps (1-4 in this example) and joining to it, but couldn't get it to work right.