October 8, 2008 at 7:28 am
HI all,
I found this code which works great and is fast.
select Col1,
(select col2 + ',' from @Tmp where col1 = a.col1 for xml path('')) as Detail
from @Tmp a group by col1
However I'm not 100% sure how it works what is the "for xml Path('')" doing?
Thanks
Chris
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
October 8, 2008 at 8:16 am
FOR XML clause generates the output in XML format and the format of the output can be controlled using AUTO, RAW, PATH and EXPLICIT.
.
October 8, 2008 at 8:49 am
ok so basically all my data is being join and return as 1 xml row?
what exactly is the PATH('') doing?
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
October 8, 2008 at 9:47 am
PATH('') instructs the XML generator not to generate a parent node for each row in the result.
This is explained in this article: http://www.sqlserverandxml.com/2008/08/for-xml-path-how-to-remove-node-from.html
.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply