码迷,mamicode.com
首页 > 其他好文 > 详细

以相同的條件,把多行記錄的某些欄位串在一起

时间:2017-04-22 12:49:12      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:iar   number   stat   ppp   work   and   string   manager   eid   



    Select Distinct
    pppo_cName As 員工姓名,
    IsNull(
        Stuff((Select ‘/‘ + IsNull(Rtrim(calculateChief.pppo_cName),‘‘) + calculateChief.pppo_cJobNumber
        From PPWWorkGroup_ppwg calculateChiefGroup
        Inner Join PPWPerson_pppo calculateChief on calculateChief.pppo_iID = calculateChiefGroup.ppwg_iCalculateChiefID
            And calculateChief.pppo_iRoleID=5 AND calculateChief.pppo_iState=1
        Where workGroup.ppwg_iID = calculateChiefGroup.ppwg_iID --與外面的配置是哪個
        group by calculateChief.pppo_cName, calculateChief.pppo_cJobNumber for xml path(‘‘)), 1, 1, ‘‘)
    ,‘‘) As 員工所屬科長,
    IsNull(SupervisorJoinString,‘‘) As 員工所屬督導
    From PPWPerson_pppo with(nolock)
    Left Join PPWPersonRole_pppr With(nolock) On pppr_iID=pppo_iRoleID
    Left Join PPWFloor_ppfl With(nolock) On ppfl_iID=pppo_iFloor
    Left Join PPWArea_ppar With(nolock) On ppar_iID=pppo_iAreaID
    Left Join PPWWorkGroup_ppwg workGroup With(nolock) On ppwg_iID=pppo_iWorkGroupID   

    Left Join
    (        
        --根據組串埋全部督導
        SELECT Distinct
                groupManager.ppwm_iWorkGroupID AS ‘GroupID‘,            
                STUFF((Select ‘;‘+ IsNull(pppo_cName,‘‘) + pppo_cJobNumber
                                From PPWWorkGroupManager_ppwm t
                                Inner Join PPWPerson_pppo on pppo_iID = t.ppwm_iPersonID
                                Where t.ppwm_iWorkGroupID = groupManager.ppwm_iWorkGroupID --與外面的配置是哪個
                                    And pppo_iRoleID=4 AND pppo_iState=1
                                --order by ppwm_iWorkGroupID
                                group by pppo_cName,  pppo_cJobNumber
                for xml path(‘‘)), 1, 1, ‘‘) As ‘SupervisorJoinString‘
        From PPWWorkGroupManager_ppwm groupManager        
    )BelongToSupervisor On BelongToSupervisor.GroupID = ppwg_iID
    where 1 = 1 And len(SupervisorJoinString)>10
   

以相同的條件,把多行記錄的某些欄位串在一起

标签:iar   number   stat   ppp   work   and   string   manager   eid   

原文地址:http://www.cnblogs.com/guyuehuanhuan/p/6747113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!