SELECT a.id,
(SELECT b. AS "@ColName",
b.value AS "text()"
FROM @t b
WHERE b.id=a.id
FOR XML PATH('Col'),ROOT('AdditionalCols'),TYPE) AS keyvalues
FROM @t a
GROUP BY a.id
ORDER BY a.id;
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537