How to combine these two SQL statements?

前端 未结 5 1229
说谎
说谎 2020-12-20 04:03

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         


        
5条回答
  •  隐瞒了意图╮
    2020-12-20 04:50

    An alternative that is similar to the other posts.

    Bob Duells post is probably the most readable.

    SELECT 
        [cntCM_PRWK]    = COUNT(CASE WHEN ws.ID_WorkflowType = 1 THEN ws.ID_WorkflowState ELSE NULL END),
        [cntCM_CMQ]     = COUNT(CASE WHEN ws.ID_WorkflowType = 3 THEN ws.ID_WorkflowState ELSE NULL 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
    

提交回复
热议问题