Struggling abit with an update to a column storing xml data in tsql. Basically I want to update the rows where a certain flag is missing. I have an advantage in that I know that if the attribute part_id=1 is present then the attribute i want to add is missing
This is an example of my output xml currently. As you can see the groupname is missing, where part is equal to 1. This is the structure in one particular row, there will be other rows to update but if I could get this example working that be a start.
<report>
<materials>
<material part_vendor_name="tests" vendor_pricing_id="wwwewew" part="1" />
<material part_vendor_name="tests" vendor_pricing_id="wwwewew" part="2" groupname="test" />
</materials>
</report>
The code to create the above structure is
declare @my_table table ( my_xml_column xml)
insert into @my_table
select '<report><materials><material part_vendor_name="tests" vendor_pricing_id="wwwewew" part="1"> </material>
<material part_vendor_name="tests" vendor_pricing_id="wwwewew" part="2" groupname="test"> </material>
</materials></report>'
I can add new elements under the report or materials flag, just can't work out on to only update the rows containing part =1
Ps. My latest attempt was the following, but i've tried many approaches
UPDATE
@my_table
SET @my_table.modify('insert <groupname> test </groupname> after (/report/materials/material)[1]')
WHERE @my_table.value('(/report/materials/material/part[text() = "1"])[1]', 'varchar(64)') = '1'
thanks mark