FOR XML PATH('') explination please

  • 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]

    SQL-4-Life
  • FOR XML clause generates the output in XML format and the format of the output can be controlled using AUTO, RAW, PATH and EXPLICIT.

    .

  • 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]

    SQL-4-Life
  • 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