Torna al Thread

USE tempdb; CREATE TABLE dbo.foo( fooID int NOT NULL PRIMARY KEY, Data xml NOT NULL ); INSERT dbo.foo VALUES (1, '<property name="items"> <name>items</name> <type>itemseditor</type> <label>Items</label> <value>PIPPO</value> <description>Edit Items</description> </property>'), (2, '<property name="items"> <name>items</name> <type>itemseditor</type> <label>Items</label> <value>PIPPO</value> <description>Edit Items</description> </property>'); DECLARE @myText varchar(10) = 'PLUTO'; /* Aggiorno l'elemento <value> solo della prima riga */ UPDATE dbo.foo SET Data.modify(' replace value of (property/value/text())[1] with sql:variable("@myText") ') WHERE fooID = 1; SELECT * FROM dbo.foo; /* Output: fooID Data ----------- --------------------------------------------------------------------------------------------------------------------------------------------------------- 1 <property name="items"><name>items</name><type>itemseditor</type><label>Items</label><value>PLUTO</value><description>Edit Items</description></property> 2 <property name="items"><name>items</name><type>itemseditor</type><label>Items</label><value>PIPPO</value><description>Edit Items</description></property> (2 row(s) affected) */ DROP TABLE dbo.foo;
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5