Suppose I have the following:
CREATE TABLE tblData ( [SourceID] int, [SourceRecID] bigint, [Value] xml )
GO
INSERT INTO tblData
VALUES
( 1, 0, N'<attributes><attribute id="58" value="0" /><attribute id="86" value="1" /><attribute id="85" value="1" /><attribute id="70" value="0" /><attribute id="38" value="0" /><attribute id="68" value="0" /><attribute id="42" value="1" /><attribute id="67" value="1" /><attribute id="62" value="1" /></attributes>' ),
( 1, 686, N'<attributes><attribute id="1" value="0.25" /><attribute id="4" value="1" /><attribute id="10" value="3" /><attribute id="11" value="1" /><attribute id="12" value="6" /></attributes>' ),
( 1, 687, N'<attributes><attribute id="1" value="2.00" /><attribute id="2" value="60.00" /><attribute id="3" value="-1" /><attribute id="5" value="252.00" /><attribute id="6" value="0" /><attribute id="7" value="1" /><attribute id="9" value="1" /><attribute id="10" value="1" /><attribute id="11" value="2" /><attribute id="12" value="10" /></attributes>' ),
( 1, 688, N'<attributes><attribute id="1" value="2.00" /><attribute id="2" value="60.00" /><attribute id="3" value="-1" /><attribute id="5" value="252.00" /><attribute id="6" value="0" /><attribute id="7" value="1" /><attribute id="11" value="2" /><attribute id="12" value="10" /></attributes>' )
GO
SELECT *
FROM tblData
Let's say I would like to delete attribute id=7 from the Value column where SourceId = 1, SourceRecID = 687.
I would expect the new value of the row SourceId = 1, SourceRecID = 687 to be:
N'<attributes><attribute id="1" value="2.00" /><attribute id="2" value="60.00" /><attribute id="3" value="-1" /><attribute id="5" value="252.00" /><attribute id="6" value="0" /><attribute id="9" value="1" /><attribute id="10" value="1" /><attribute id="11" value="2" /><attribute id="12" value="10" /></attributes>' ),
Notice that <attribute id="7" value="1" /> is now missing from the original xml for that row.
I can't think of a way to do it...
DELETE FROM tblData WHERE SourceID = 1;would delete every row, why do the latter 2 requirements matter?Valuefield in that row. I hope that makes it clearer.UPDATE HR_XML SET Salaries.modify('delete (/Salaries/Accounting)[2]'). I didn't know that until now by the way