xml.modify

SQL Server append XML child nodes to parent node

让人想犯罪 __ 提交于 2020-01-01 06:56:15
问题 I need to have a script which can insert / append new xml child nodes to a pre-existing xml parent node. --New child nodes DECLARE @XMLChildData XML SET @XMLChildData = ' <Persons> <Person> <Firstname>Gary</Firstname> <Surname>Smith</Surname> <Telephone>0115547899</Telephone> <Address> <AddressLine>1 Church Lane</AddressLine> <AddressLine>Rosebank</AddressLine> <AddressLine>Houghton</AddressLine> <AddressLine>South Africa</AddressLine> </Address> </Person> <Person> <Firstname>Wayne</Firstname

Remove Varying levels of empty XML tags in SQL Server

天涯浪子 提交于 2019-12-11 07:44:41
问题 I am using FOR XML EXPLICIT to union to convert some SQL table info into an XML file. It's all working, but I have loads of empty tags in the results, at all sorts of different levels. I would like to remove all the empty tags, but keep the top level for each group. Here's an example of the sort of thing I mean: Using this example bit of nonsense XML, I can remove the bottom level empty nodes with a .modify xquery: DECLARE @XML XML = '<Whatever> <GlassesTypes> <GlassesType /> </GlassesTypes>

SQL Server append XML child nodes to parent node

拜拜、爱过 提交于 2019-12-03 17:07:04
I need to have a script which can insert / append new xml child nodes to a pre-existing xml parent node. --New child nodes DECLARE @XMLChildData XML SET @XMLChildData = ' <Persons> <Person> <Firstname>Gary</Firstname> <Surname>Smith</Surname> <Telephone>0115547899</Telephone> <Address> <AddressLine>1 Church Lane</AddressLine> <AddressLine>Rosebank</AddressLine> <AddressLine>Houghton</AddressLine> <AddressLine>South Africa</AddressLine> </Address> </Person> <Person> <Firstname>Wayne</Firstname> <Surname>Farmey</Surname> <Telephone>0117453269</Telephone> <Address> <AddressLine>51 Oak Street<