sql-serverxmlsql-server-2008xquery

Merge the two xml fragments into one?


How to merge the xml content of @a and @b into @c?

declare @a xml = (select 1 aaa for xml path('AAAs'));
declare @b xml = (select 1 bb1, 2 bb2 for xml path('BBBs'));
declare @c xml = ... @a + @b ....?

I need to pass the merged xml to a stored procedure.


I know it's possible to cast the xml to varchar and concat them and convert it back to xml. Any better approach? The xml content can be big.


Solution

  • OK, I found one way

    select @a, @b for xml path ('')