Union Xml Output

  • Hi,

    is there a way to do a union over two or more instances for xml???

    something like this:

    Select field1, field2

    from table1

    FOR XML RAW('Node1'), Elements

    Union

    Select field1, field2

    from table2

    FOR XML RAW('Node2'), Elements

    where field1 and field2 are the same data type.

    I tested it, but not works, but is there a way to do it?

    Thanks in advanced.

  • Try insert both results in to a table variable if UNION doesn't work.

  • This was removed by the editor as SPAM

  • Can we assume that both tables are identical except for the output node name? The XML AUTO (or PATH) and UNION would work that way - but if the tables are different - it wouldn't.

  • If the table schemas are different and a direct UNION won't work - I would suggest:

    SELECT ( SELECT field1

    , field2

    FROMtable1

    FOR XML PATH('Node1'), ELEMENTS, TYPE)

    , ( SELECTfield1

    , field2

    FROMtable1

    FOR XML PATH('Node2'), ELEMENTS, TYPE)

    FOR XML PATH('Root')

Viewing 5 posts - 1 through 4 (of 4 total)

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