I have 2 SQL queries both of which get the counts for different IDs.
select @cntCM_CMQ = count(*)
from dbo.CaseWorkflow cw
join vew_CasePersonnelSystemIDs
There's a trick to doing this. essentially you use Case to pick out a 1 value for the rows you are interested in and then Sum the ones to get a count. Case defaults to null if no cases match, which get ignored by Sum
Select
@cntCM_CMQ = Sum(Case ws.ID_WorkflowType When 3 Then 1 End),
@cntCM_PRWK = Sum(Case ws.ID_WorkflowType When 1 Then 1 End)
From
dbo.CaseWorkflow cw
inner join
vew_CasePersonnelSystemIDs vcps
on cw.ID_Case = vcps.ID_Case
inner join
dbo.WorkflowStates ws
on ws.ID_WorkflowState = cw.ID_WorkflowState
Where
CMSUID = @nSUID