我想將屬性值添加到查詢中的xml字段。我的例子如下將列值添加到xml字段作爲屬性
declare @table table (bookid int,xmlCol xml)
insert into @table
select 1,
'<book title="you are not alone" author="Esther">
<EDITIONS>
<edition year="2012"/>
<edition year="2013"/>
</EDITIONS>
</book>'
declare @table1 table(bookid int,quantity int)
insert into @table1
select 1,3
select ???
from @table t
inner join @table1 t1
on t.bookid = t1.bookid
我希望我的最後的結果看起來像這樣
<book title="you are not alone" author="Esther" quantity="3">
<EDITIONS>
<edition year="2012"/>
<edition year="2013"/>
</EDITIONS>
</book>
第一個解決方案的工作原理,但有另一種方法來解決這個問題嗎?我最好不要改變表中的xml結構 – user829982