本文介绍了即使fullname没有用逗号分隔,当两个人的任务相同时使用stuff为fullname的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT DISTINCT
STUFF((SELECT distinct ', ' + U1.FullName
from TM_user U1
where u.TM_UserID = U1.TM_UserID
FOR XML PATH ('')
), 1, 2, '') FullName,
推荐答案
;WITH temp as
(
SELECT DISTINCT
u.TM_UserID
task_name
FROM
project
JOIN task
ON project.project_id=task.project_id
JOIN timesheet
ON timesheet.task_id=task.task_id
JOIN Team
ON project.project_id = Team.project_id
JOIN TM_user u
ON u.TM_userID=timesheet.user_id
WHERE u.Is_Active=1
AND u.report_to=13
AND worked_dte BETWEEN '2014-03-18' AND '2014-03-21'
)
select
task_name
,STUFF(
(
SELECT ', ' + U1.FullName
from TM_user
INNER JOIN temp ON temp.task_name = temptbl.task_name
FOR XML PATH ('')
),
1,
2,
''
) FullName
from temp temptbl
Group BY task_name
快乐编码!
:)
Happy Coding!
:)
这篇关于即使fullname没有用逗号分隔,当两个人的任务相同时使用stuff为fullname的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!