下面是XML文件结构和我用来生成它的代码。 table_1中有300个uniq_id行。如下所示我只为一条记录生成,即uniq_id = 7725.但我想为这些id生成300 xml文件。我很难发现如何生成它们并在table_2中更新这些具有外键uniq_id字段的xml文件。谢谢你的回复。
----------- XML file template -----------
<Value>
<Gov_1>
<data>
<id>radio_option</id>
<value>7725</value>
<tag />
<visible>true</visible>
</data>
</Gov_1>
<Gov_2>
<data>
<id>radioType</id>
<value>7725</value>
<tag />
<visible>true</visible>
</data>
</Gov_2>
</Value>
------------------------------------------
Code that I wrote to generate it.
;WITH radio_option AS
(
Select 'radio_option' as id,
d.uniq_id as value,
'' as tag,
'true' as visible,
FROM table_1 d
where d.uniq_id = 7725
) ,
radioType AS (
Select 'radioType' as id,
d.uniq_id as value,
'' as tag,
'true' as visible,
d.uniq_id
FROM table_1 d
where d.uniq_id = 7725
)
select
(
select t1.id, t1.value, t1.tag, t1.visible
from radio_option t1
FOR XML PATH('data'),ROOT('Gov_1'), TYPE ),
(
select t2.id, t2.value, t2.tag, t2.visible
from radioType t2
FOR XML PATH('data'),ROOT('Gov_2'), TYPE
)
FOR XML PATH('Value')
----------
Table 1 (
uniq_id int, (pk)
add_name varchar(150),
contact_name varchar(150),
location varchar(150),
company name varchar(150),
date_t datetime
)
Table 2
(
table_2_rid int,
uniq_id int (fK),
perm_id int,
add_id int,
Xml_file xml,
date_t, datetime
)
Table 1
uniq_id add_name contact_name location company_name date_t
7725 abcd Victor CA XYZ 8/7/2016
7726 dfre Angelic FL FHT 8/7/2016
Table 2
table_2_rid uniq_id perm_id add_id Xml_file date_t
1 7725 3847 2345 xml_file_7725 8/7/2016
2 7726 4578 5432 xml_file_7726 8/7/2016