Mega Code Archive

 
Categories / MSSQL Tutorial / XML
 

Modifying XML Data

3> 4> CREATE TABLE dbo.ProductBilling 5> (ProductBillingID int IDENTITY(1,1) PRIMARY KEY, 6> ProductBillingXML XML NOT NULL) 7> GO 1> 2> INSERT dbo.ProductBilling(ProductBillingXML) 3> VALUES ('<ProductBilling Billingnumber="1" customerid="22" orderdate="7/1/2005"> 4~ <OrderItems> 5~ <Item id="22" qty="1" name="SQL"/> 6~ <Item id="24" qty="1" name="T-SQL"/> 7~ </OrderItems> 8~ </ProductBilling>') 9> GO (1 rows affected) 1> 2> INSERT dbo.ProductBilling 3> (ProductBillingXML) 4> VALUES ('<ProductBilling Billingnumber="1" customerid="40" orderdate="7/11/2005"> 5~ <OrderItems> 6~ <Item id="11" qty="1" name="Notes"/> 7~ </OrderItems> 8~ </ProductBilling>') 9> GO (1 rows affected) 1> 2> INSERT dbo.ProductBilling 3> (ProductBillingXML) 4> VALUES ('<ProductBilling Billingnumber="1" customerid="9" orderdate="7/22/2005"> 5~ <OrderItems> 6~ <Item id="11" qty="1" name="SQL Notes"/> 7~ <Item id="24" qty="1" name="T-SQL Notes"/> 8~ </OrderItems> 9~ </ProductBilling>') 10> GO (1 rows affected) 1> 2> set quoted_identifier off 3> 4> UPDATE dbo.ProductBilling 5> SET ProductBillingXML.modify 6> ('insert <Item id="920" qty="1" name="SQL Server 2005 T-SQL Recipes"/>into (/ProductBilling/OrderItems)[1]') 7> WHERE ProductBillingID = 2 8> 9> set quoted_identifier on 10> 11> drop table dbo.ProductBilling 12> GO (1 rows affected)