我有这样的表employee_table
org employeeid (int) firstname lastname
1234 56788934 Suresh Raina
1234 56793904 Virat Kohli
然后我有像这样的project_table
Project members (varchar)
A123 56788934,56793900
现在我需要像这样在一行中获取相应的员工姓名和东西。
Project members (varchar)
A123 Suresh Raina, Virat Kohli
我在下面写了不起作用的查询。请帮忙。
SELECT project,
(
SELECT message_text = Stuff(
(
SELECT ', ' + Concat(firstname,' ',lastname)
FROM employee_table t1
WHERE t1.org = t2.org
AND CONVERT(VARCHAR,t1.userid) IN (Concat('''',Replace(pt.members,',',''','''),'''')) --adding single quotes at start and end of each number
FOR xml path ('')) , 1, 1, '')
FROM employee_table t2
WHERE t2.userid IN
group BY org;) FROM project_table pt