9

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.

ca9163d9
  • 27,283
  • 64
  • 210
  • 413
  • I would try to just query the XML variables using `for xml`. I'm not at a computer right now but something like this could work. `select @a as A, @b as B for xml path('root')` – Mikael Eriksson Mar 19 '12 at 21:58

1 Answers1

26

OK, I found one way

select @a, @b for xml path ('')
ca9163d9
  • 27,283
  • 64
  • 210
  • 413