2,209
社区成员
发帖
与我相关
我的任务
分享
select a.*,c.UserTypeName,c.UserTypeId,d.DEPT_NAME,d.Dept_code
from (select *,newNum=ROW_NUMBER() over(order by User_Code)
from His_User_Dict where User_Code !='admin' and User_Dept_Code = 'HX ' ) as a
left join his_Dept_Dict d on a.User_Dept_code = d.DEPT_CODE
left join (select User_Code, User_Dept_Code, UserTypeId=stuff((select ','+ CONVERT(varchar(10), UserTypeID)
from (select bb.*,aa.User_Code,aa.User_Dept_Code
from dbo.UserInfoType aa left join dbo.UserType bb on aa.UserTypeId = bb.UserTypeId) t
where t.User_Code = a.User_Code and t.User_Dept_Code=a.User_Dept_Code for xml path('')), 1, 1, '') ,
UserTypeName=stuff((select '',''+ CONVERT(varchar(10), UserTypeName) from (select bb.*,aa.User_Code,aa.User_Dept_Code from dbo.UserInfoType aa left join dbo.UserType bb on aa.UserTypeId = bb.UserTypeId) t
where t.User_Code = a.User_Code and t.User_Dept_Code=a.User_Dept_Code for xml path('')), 1, 1, '')
from (select bb.*,aa.User_Code,aa.User_Dept_Code from dbo.UserInfoType aa left join dbo.UserType bb on aa.UserTypeId = bb.UserTypeId) a
group by User_Code, User_Dept_Code) c on a.User_Code = c.User_Code and a.User_Dept_Code = c.User_Dept_Code
where newNum between 1 and 30 order by newNum asc
;