--Works good with numbers, careful with text due to xml-conversion select stuff( ( select ','+AnimalId from dbo.Animal as a for xml path('') ), 1,1,'') AS AggregatedAnimalIdsAsString
Ignore namespaces! "select @xmlDoc.query('data(/*:authors/*:child/*:id)') as UserID" from blog post http://maxbarrass.blogspot.se/2008/02/sql-2005-xml-xquery-ignore-namespaces.html