wrap xml column values into outer for xml path query

  • I want to wrap the xml from a column into an out for xml path query without

    the column name as an element.

    declare @tab table (col xml)

    insert @tab

    select '<element/>'

    select 'val' AS "@att" , col

    from @tab

    for xml path ('ROOT')

    This gives

    <ROOT att="val">

    <col>

    <element />

    </col>

    </ROOT>

    but i want

    <ROOT att="val">

    <element />

    </ROOT>

    All help most appreciated.

    www.sql-library.com[/url]

  • There's probably a better way, but doing a meaningless cast or similar so that the output column has no name acheives this result:

    declare @tab table (col xml)

    insert @tab

    select '<element/>'

    select 'val' AS "@att" , CAST(col AS XML)

    from @tab

    for xml PATH ('ROOT')

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply