本版本仅限于3.5版本,不适用于4.5及以上。
第一个版本如下:
SELECT
[BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount] AS ExtRecipient
,COUNT([BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount]) AS Quantity
FROM [BPMDB].[dbo].[BPMInstProcSteps] INNER JOIN [BPMDB].[dbo].[BPMInstTasks] ON [BPMDB].[dbo].[BPMInstProcSteps].[TaskID] = [BPMDB].[dbo].[BPMInstTasks].[TaskID]
WHERE [BPMDB].[dbo].[BPMInstTasks].[State] = 'Running'
AND [BPMDB].[dbo].[BPMInstProcSteps].[FinishAt] IS NULL AND [BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount] <> 'waibpm' AND [BPMDB].[dbo].[BPMInstProcSteps].[NodeName] <> 'Start'
GROUP BY [BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount]
ORDER BY [BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount]
有个问题,就是一旦任务被处理人手动或自动转给助理/代理人,这个数据就不准了。所以就有了第二个版本:
SELECT
ISNULL([BPMDB].[dbo].[BPMInstProcSteps].[AgentAccount],[BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount]) AS ExtRecipient
,COUNT(*) AS Quantity
FROM [BPMDB].[dbo].[BPMInstProcSteps] INNER JOIN [BPMDB].[dbo].[BPMInstTasks] ON [BPMDB].[dbo].[BPMInstProcSteps].[TaskID] = [BPMDB].[dbo].[BPMInstTasks].[TaskID]
WHERE [BPMDB].[dbo].[BPMInstTasks].[State] = 'Running'
AND [BPMDB].[dbo].[BPMInstProcSteps].[FinishAt] IS NULL
AND [BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount] <> 'waibpm'
AND [BPMDB].[dbo].[BPMInstProcSteps].[NodeName] <> 'Start'
GROUP BY ISNULL([BPMDB].[dbo].[BPMInstProcSteps].[AgentAccount],[BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount])
ORDER BY ISNULL([BPMDB].[dbo].[BPMInstProcSteps].[AgentAccount],[BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount])
这个SQL写得并不好,因为GROUP BY和ORDER BY里面还有运算。最好写一个UNION将有AgentAccount和没有AgentAcount的单独筛选一下,然后再来汇总。
如果数据量不大,用这个也无妨。
另外附上在AutoMate中调度这个SQL,然后自动发送邮件的细节,供参考(图可以下载后放大看)。