I'm looking to create a SQL Server query that will combine resources with the same Task into one row/record string using three tables. My SQL Server query below doesn't seem to be working correctly and takes a very long time to execute and then errors out. Thanks!
Task Table
TaskUID
TaskName
Assignment Table
TaskUID
ResourceUID
Resource Table
ResourceUID
ResourceName
Before
**Task Name Resource Name**
Weapon Launch Amy
Weapon Launch Sam
Weapon Launch Marisa
Weapon Launch Katy
Weapon Launch John
Sweating Tears Marisa
Sweating Tears Joe
Sweating Tears Katy
Sweating Tears Michael
Ramp Diver Joe
Ramp Diver Michael
After
**Task Name Resource Name**
Weapon Launch Amy; Sam; Marisa; Katy; John
Sweating Tears Marisa; Joe; Katy; Michael
Ramp Diver Michael; Joe
Query
SELECT T.TaskName,
STUFF(( SELECT ', ' + R.RESOURCENAME
FROM
[Resource Table] R
LEFT JOIN [Assignment Table] A ON R.ResourceUID=A.ResourceUID
WHERE
A.TASKUID=T.TaskUID
Group by R.RESOURCENAME
FOR XML PATH('')), 1, 1,'') Resources
FROM [Task Table] T
INNER JOIN [Assignment Table] A ON T.TASKUID=A.TASKUID
Please try:
SQL Fiddle