CREATE VIEW VWPMO_WF_OVERVIEW_AUTHORITY AS
SELECT 
	T.GUID as WF_ID,
	T.RECORD_ID,       
	TBPMO_WORKFLOW.TITLE + ' - ' + TBPMO_WORKFLOW_TASK_STATE.STATE_DESC AS STATE, 
	TBPMO_WORKFLOW_TASK_STATE.GUID AS STATE_ID,
	TBPMO_WORKFLOW_TASK_STATE.COLOR,
	(SELECT        TBDD_USER.NAME + ', ' + TBDD_USER.PRENAME AS Expr1
	FROM            TBPMO_WORKFLOW_TASK_USER INNER JOIN
								TBDD_USER ON TBPMO_WORKFLOW_TASK_USER.USER_ID = TBDD_USER.GUID
	WHERE        (TBPMO_WORKFLOW_TASK_USER.WF_TASK_ID = T.GUID)) AS Authority,
	CASE WHEN (SELECT        TBDD_USER.NAME + ', ' + TBDD_USER.PRENAME AS Expr1
	FROM            TBPMO_WORKFLOW_TASK_USER INNER JOIN
								TBDD_USER ON TBPMO_WORKFLOW_TASK_USER.USER_ID = TBDD_USER.GUID
	WHERE        (TBPMO_WORKFLOW_TASK_USER.WF_TASK_ID = T.GUID)) IS NULL
      THEN TBPMO_WORKFLOW.TITLE + ' - ' + TBPMO_WORKFLOW_TASK_STATE.STATE_DESC
      ELSE 
		TBPMO_WORKFLOW.TITLE + ' - ' + TBPMO_WORKFLOW_TASK_STATE.STATE_DESC + ' - ' + 
		(SELECT        TBDD_USER.NAME + ', ' + TBDD_USER.PRENAME AS Expr1
	FROM            TBPMO_WORKFLOW_TASK_USER INNER JOIN
								TBDD_USER ON TBPMO_WORKFLOW_TASK_USER.USER_ID = TBDD_USER.GUID
	WHERE        (TBPMO_WORKFLOW_TASK_USER.WF_TASK_ID = T.GUID))
	END AS String,
	T.CHANGED_WHO,
	T.CHANGED_WHEN
FROM            TBPMO_WORKFLOW_TASK T INNER JOIN
                         TBPMO_WORKFLOW ON T.WF_ID = TBPMO_WORKFLOW.GUID INNER JOIN
                         TBPMO_WORKFLOW_TASK_STATE ON T.STATE_ID = TBPMO_WORKFLOW_TASK_STATE.GUID
WHERE        (T.ACTIVE = 1)