SELECT TOP 10 substring(O.Functions,2,500) FROM dbo.Tp_Person P CROSS APPLY ( SELECT ',' + CAST(FunctionName AS varchar) AS [text()] FROM dbo.Tp_Function F WHERE F.Personid = P.Personid FOR XML PATH('') ) O( Functions )This trick actually reduced the time of the procedure on 5000 people from about 30 seconds to 1,5 seconds. Made my day.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.