Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 21st, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to modify xml node in sql server
  2. <root>
  3.       <Category>Cover Impression</Category>
  4.       <Title>Mystery of the Wolves</Title>
  5.       <Month>April</Month>
  6.       ...
  7.       ...
  8.     </root>
  9.        
  10. <Category>Cover Impressions</Category>
  11.        
  12. declare @newValue XML
  13. select @newValue = 'Cover Impressions'
  14. update dbo.content
  15. set content_html.modify('replace value of (/root/Category/text())[1] with sql:variable("@newValue")')
  16.        
  17. <Sample>
  18.   <NodeOne>Value1</NodeOne>
  19.   <NodeTwo>Value2</NodeTwo>
  20.   <NodeThree>OldValue</NodeThree>
  21. </Sample>
  22.        
  23. DECLARE @newValue varchar(50)
  24.  SELECT @newValue = 'NewValue'
  25.  
  26.  UPDATE [Product]
  27.  SET ProductXml.modify('replace value of (/Sample/NodeThree/text())[1] with sql:variable("@newValue")')
  28.        
  29. ALTER TABLE dbo.YourTable
  30.   ALTER COLUMN Content_Html XML
  31.        
  32. UPDATE dbo.YourTable
  33. SET Content_Html.modify('replace value of (/root/Category/text())[1] with "Cover Impressions"')
  34. WHERE ...(whatever condition need here).....