Inner join case when

                                    SELECT ( '#' + CONVERT(NVARCHAR(20), wn.ActualWorkflowNumber)
                                               + ' ' + wi.SN ) AS SN ,
                                             wi.RecordID ,
                                             wi.WorkflowName ,
                                             wc.WorkflowDisplayName,
                                             wi.WorkflowVersion,
                                             wi.SubmitUser ,
                                             -- 外部生成提交用户中文名
                                             wi.SubmitTime ,
                                             -- 外部生成任务url
                                             n.ApproveNode AS WorkflowCurrentNodeDisplayName ,
                                             n.ApproveNodeInternalName AS WorkflowCurrentNode ,
                                             n.ApproveUser ,
                                             n.WorkflowInstanceID,
                                             isnull(n.CreateTime,'2000-1-1') as WorkflowNodeEntryTime,
                                             -- 外部生成审批用户中文名称集合
                                             wc.ClientApp,
                                             r.AllowEmailApprove,
                                             r.AllowDingTalkApprove,
                                             -- 外部生成审批动作
                                             wi.BusinessCode ,
                                             bc.BusinessCodeFieldDesc ,
                                             -- 外部生成流程描述
                                             wi.FormData,
                                             1 AS ItemType
                                    FROM     dbo.BPM_WorkflowNodes n WITH(NOLOCK)
                                             INNER JOIN dbo.BPM_WorkflowInstance wi WITH(NOLOCK) ON n.WorkflowInstanceID = wi.ID
                                             INNER JOIN dbo.WF_WorkflowNumber wn WITH(NOLOCK) ON wi.RecordID = wn.RecordId
                                             LEFT JOIN dbo.BPM_WorkflowConfig wc WITH(NOLOCK) ON wi.WorkflowName=wc.WorkflowName AND wi.WorkflowVersion=wc.Version

                                             LEFT JOIN dbo.EES_Resource r WITH(NOLOCK) ON 
                                             
                                             CASE WHEN CHARINDEX('#',n.ApproveNodeInternalName)>0
                                             THEN n.WorkflowName+'.'+SUBSTRING(n.ApproveNodeInternalName,1,CHARINDEX('#',n.ApproveNodeInternalName)-1)
                                             ELSE n.WorkflowName+'.'+n.ApproveNodeInternalName END  =r.ResourceName
                                             
                                             LEFT JOIN dbo.WF_BusinessCode bc WITH(NOLOCK) ON wi.WorkflowName = bc.WorkflowName
                                    WHERE    n.ID IN ('74d4c2da-8260-4574-9674-56f39a820e5d') AND r.AllowDingTalkApprove=1--4baccfa2-3df2-4690-9066-9a24fc42b524

 

posted @ 2017-10-23 14:21  直钩钓鱼  阅读(2597)  评论(2编辑  收藏  举报