Great article, this may solve the problem I had with this code that would have been considerably faster than Coalesce.
-- create list to pivot hist data
SELECT @DistList =
COALESCE(@DistList + ',[', '[') +
CAST(Dist AS VarCHAR(85)) + ']'
FROM (
SELECT top 1000 Disty
FROM @t1
Order by Disty
) t(Dist)
-- try for XML to speed up the coalesce -- may bug on Shangai P&S
--Select @DistList = (
--SELECT Disty + ', ' As [text()]
--FROM @t1
--ORDER BY Disty
--FOR XML PATH('')
--)
--Set @DistList = LEFT(@DistList, Len (@DistList) -1)
BI Guy