
Untitled
By: a guest on
May 21st, 2012 | syntax:
None | size: 0.93 KB | hits: 10 | expires: Never
how to modify xml node in sql server
<root>
<Category>Cover Impression</Category>
<Title>Mystery of the Wolves</Title>
<Month>April</Month>
...
...
</root>
<Category>Cover Impressions</Category>
declare @newValue XML
select @newValue = 'Cover Impressions'
update dbo.content
set content_html.modify('replace value of (/root/Category/text())[1] with sql:variable("@newValue")')
<Sample>
<NodeOne>Value1</NodeOne>
<NodeTwo>Value2</NodeTwo>
<NodeThree>OldValue</NodeThree>
</Sample>
DECLARE @newValue varchar(50)
SELECT @newValue = 'NewValue'
UPDATE [Product]
SET ProductXml.modify('replace value of (/Sample/NodeThree/text())[1] with sql:variable("@newValue")')
ALTER TABLE dbo.YourTable
ALTER COLUMN Content_Html XML
UPDATE dbo.YourTable
SET Content_Html.modify('replace value of (/root/Category/text())[1] with "Cover Impressions"')
WHERE ...(whatever condition need here).....