SQL Server append XML child nodes to parent node

拜拜、爱过 提交于 2019-12-03 17:07:04

Extract the Person nodes from @XMLChildData to a separate variable and add that to the Persons node of @XMLParentData.

DECLARE @PersonList XML

SET @PersonList = @XMLChildData.query('Persons/*')

SET @XMLParentData.modify('insert sql:variable("@PersonList") as last into /Persons[1]')

SELECT @XMLParentData

Another way is to extract the Person nodes from both variables and rebuild the Persons node using FOR XML PATH.

SET @XMLParentData = (
                     SELECT @XMLParentData.query('/Persons/Person'),
                            @XMLChildData.query('/Persons/Person')
                     FOR XML PATH(''), ROOT('Persons'), TYPE
                     )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!