Let's have a sample snippet:
DECLARE @xml XML = N'
<a abb="122">
<b>
</b>
</a>
';
SELECT @xml;
--need to update abb to be 344 in @xml here
SELECT @xml;
I don't know how to update that attribute abb
's value.
To update data in an XML column, use the SQL UPDATE statement. Include a WHERE clause when you want to update specific rows. The entire column value will be replaced. The input to the XML column must be a well-formed XML document.
Create columns and variables CREATE TABLE T1(Col1 int primary key, Col2 xml); You can use a DECLARE statement to create a variable of xml type, as the following example shows. DECLARE @x xml; Create a typed xml variable by specifying an XML schema collection, as shown in the following example.
A.The value() method retrieves the ProductID attribute value from the XML. The value is then assigned to an int variable. Value 1 is returned as a result.
The modify() is the DML based function with an argument of XPATH to perform insert, update or delete the elements or attributes with the XML based column in the table.
set @xml.modify('replace value of (/a/@abb)[1] with 344')
Read more about it here. XML Data Modification Language (XML DML)
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