Modify the xml column

Hi TSQL experts

Need a help on modifying the xml column. I have column "METADATA" in tbl_srcmtr and here is the sample records.

id Monitor Interval Metadata Eventid
1 A1 80 <Properties Id="1" /> 1024
2 A1 80 <Properties Id="2" /> 1024
3 A1 80 <Properties Id="3" /> 1024
4 A1 80 <Properties Id="4" /> 1024
5 A2 80 <Properties Id="1" /> 1024
6 A2 80 <Properties Id="2" /> 1024
7 A2 80 <Properties Id="3" /> 1024
8 A2 80 <Properties Id="4" /> 1024

I wanted to modify all the <Properties Id="3" /> to <Properties Id="10"

July 9th, 2015 9:08pm

like this ??
DECLARE @T TABLE(id	INT,Monitor	CHAR(2),Interval INT,Metadata XML,Eventid INT)
INSERT INTO @t 
VALUES 
 (1,'A1',80,'<Properties Id="1" />',1024)
,(2,'A1',80,'<Properties Id="2" />',1024)
,(3,'A1',80,'<Properties Id="3" />',1024)
,(4,'A1',80,'<Properties Id="4" />',1024)
,(5,'A2',80,'<Properties Id="1" />',1024)
,(6,'A2',80,'<Properties Id="2" />',1024)
,(7,'A2',80,'<Properties Id="3" />',1024)
,(8,'A2',80,'<Properties Id="4" />',1024)



update @t SET Metadata.modify(' replace value of (/Properties/@Id)[.="3"][1] with "10"')

select * FROM @t 

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2015 1:17am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics