SELECT
DISTINCT wq.workQueueID,
wq.name,
ou.name,
wqs.subscriberType,
COUNT(taskID)
INTO
:workQueueID,
:workQueueName,
:subscriberName,
:subscriberType,
:taskCount
FROM
WorkQueue wq
LEFT
JOIN
TaskAssignment ta
ON wq.workQueueID = ta.relatedID
AND ta.assigneeType = :workQueue,
WorkQueueSubscription wqs,
OrganisationUnit ou
WHERE wqs.subscriberType = :subscriberType
AND wq.workQueueID = wqs.workQueueID
AND ou.organisationUnitID = wqs.subscriberID
AND wqs.subscriberID IN
(
SELECT
DISTINCT ou.organisationUnitID
FROM
Users u,
PositionHolderLink ph,
Position p,
OrgUnitPositionLink oup,
OrganisationUnit ou
WHERE u.userName = :userName
AND u.userName = ph.userName
AND ph.positionID = p.positionID
AND p.positionID = oup.positionID
AND oup.organisationUnitID = ou.organisationUnitID
AND ph.recordStatus <> :recordStatus
AND
(
(
ph.fromDate <= :currentDate
AND ph.toDate IS NULL
)
OR
(
ph.fromDate <= :currentDate
AND ph.toDate >= :currentDate
)
)
)
GROUP
BY wq.workQueueID,
wq.name,
ou.name,
wqs.subscriberType
ORDER BY wq.name
|