Merge the two xml fragments into one?

ca9163d9 picture ca9163d9 · Mar 19, 2012 · Viewed 11.1k times · Source

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.

Answer

ca9163d9 picture ca9163d9 · Mar 19, 2012

OK, I found one way

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