Add attribute to root element

How to add an attribute to the root element of any XML documents, which is a column in a table called book

this table contains bookid int
                    title  varchar(10)
                    Author varchar(10)
                    Order XML

order is the xml object in this table and contains the following

<buyOrder ordernum="10">
  <date>2010-12-3</date>
  <shippingdate>2010-12-5</shippingdate>
  <delivery>2010-12-12</delivery>
</buyOrder>

I want to add an attribute called cost to the root element?

How can i do this?

+3
source share
1 answer
declare @Cost money = 10  

update book set
  [Order].modify('insert attribute cost {sql:variable("@Cost")} into (buyOrder[1])')
+2
source

Source: https://habr.com/ru/post/1795070/


All Articles