There is no way to add elements to existing XML in a query. You can however recreate the XML using the XML itself and adding the new elements or attributes you need.
Roman Pekar showed in his answer to your other question a technique you can use and if you understand what he does you should be able to adapt that answer to work for you here.
You need to create a new root element book
, add the attributes from the existing element book, add the sub elements from book and finally add the new element using sql:column
to pull in the value.
select T.xmlCol.query('element book {
book/@*, (:Add attributes from root node:)
book/*, (:Add sub nodes from root node:)
element seller (:Add the new element:)
{sql:column("T1.seller")} (:Get the value for the new node:)
}')
from @table as T
inner join @table1 as T1
on T.bookid = T1.bookid