insert (XML DML)を使用して XML 変数を変更できます。
新しい XML 変数に挿入する XML を作成し、.xml を使用してその XML を XML 変数に挿入しますsql:variable()
。
-- XML to change
declare @XML xml
set @XML =
'<root>
<ati id_ati="16546" />
</root>'
-- Table holding data to insert
declare @T table(id_ati int)
insert into @T values(344),(566),(788),(545)
-- Build the XML you want to add
declare @X xml
set @X =
(
select id_ati as "@id_ati"
from @T
for xml path('ati')
)
-- Modify your XML
set @XML.modify('insert sql:variable("@X") as last into root[1]')
-- View the result
select @XML
テーブル変数@T
を、データを取得するために必要なクエリに置き換えます。の XML は@X
次のようになります。
<ati id_ati="344" />
<ati id_ati="566" />
<ati id_ati="788" />
<ati id_ati="545" />