XML Storage can have zero or more <Address>
nodes under <Addresses>
Need a query to delete any <Address>
nodes whose <AddressLine> = '2 Church Lane'
Starting XML:
declare @t table (storage xml);
insert into @t (storage)
select '<Person>
<Fullname />
<Surname>Smith</Surname>
<FirstName>John</FirstName>
<Addresses>
<Address>
<AddressLine>1 Church Lane</AddressLine>
</Address>
<Address>
<AddressLine>2 Church Lane</AddressLine>
</Address>
<Address>
<AddressLine>3 Church Lane</AddressLine>
</Address>
</Addresses>
</Person>';
Resulting XML:
<Person>
<Fullname />
<Surname>Smith</Surname>
<FirstName>John</FirstName>
<Addresses>
<Address>
<AddressLine>1 Church Lane</AddressLine>
</Address>
<Address>
<AddressLine>3 Church Lane</AddressLine>
</Address>
</Addresses>
</Person>
Found it:
update @t
SET storage.modify('
delete (/Person/Addresses/Address[AddressLine = "2 Church Lane"])
')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With