次の表があります。
CREATE TABLE PLMXC_ERP_INT_XML_BOM
(
admi_num int,
stlh_num varchar(20),
arti_oms_1 varchar(40),
arti_code varchar(20),
stlx_pos varchar(5),
stlx_aantal numeric(16,6)
);
次の内容で:
INSERT INTO PLMXC_ERP_INT_XML_BOM
(admi_num, stlh_num, arti_oms_1, arti_code, stlx_pos, stlx_aantal)
VALUES
(1, '3P-2000245', 'Cover 2 undercolum 1MF', '3P-2000242', '1', 1),
(1, '3P-2000245', 'Cover 2 undercolum 1MF', '3P-2000243', '2', 1),
(1, '3P-2000245', 'Cover 2 undercolum 1MF', '3P-101707', '3', 5),
(1, '3P-101707', 'cover 1MF undercolumn', '3P-2000242', '1', 1),
(1, '3P-101707', 'cover 1MF undercolumn', '3P-2000243', '2', 1);
このコンテンツから XML を作成する場合に使用します
SELECT stlh.admi_num
,stlh.stlh_num
,stlh.arti_oms_1 as stlh_oms_1
,(SELECT
admi_num
,stlm.arti_code
,ROW_NUMBER()OVER(PARTITION BY stlm.stlh_num ORDER BY stlm.stlh_num) as stlm_num
,stlx_pos as stlm_pos
,stlx_aantal as stlm_aantal
FROM PLMXC_ERP_INT_XML_BOM stlm
WHERE stlm.stlh_num = stlh.stlh_num
FOR XML AUTO, TYPE, ELEMENTS
)
FROM [PLMXC_ERP_INT_XML_BOM] stlh
GROUP BY stlh.stlh_num, stlh.admi_num, stlh.arti_oms_1
FOR XML AUTO, ELEMENTS
そして、これは私を返します
<stlh>
<admi_num>1</admi_num>
<stlh_num>3P-101707</stlh_num>
<stlh_oms_1>cover 1MF undercolumn</stlh_oms_1>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-2000242</arti_code>
<stlm_num>1</stlm_num>
<stlm_pos>1</stlm_pos>
<stlm_aantal>1.000000</stlm_aantal>
</stlm>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-2000243</arti_code>
<stlm_num>2</stlm_num>
<stlm_pos>2</stlm_pos>
<stlm_aantal>1.000000</stlm_aantal>
</stlm>
</stlh>
<stlh>
<admi_num>1</admi_num>
<stlh_num>3P-2000245</stlh_num>
<stlh_oms_1>Cover 2 undercolum 1MF</stlh_oms_1>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-2000242</arti_code>
<stlm_num>1</stlm_num>
<stlm_pos>1</stlm_pos>
<stlm_aantal>1.000000</stlm_aantal>
</stlm>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-2000243</arti_code>
<stlm_num>2</stlm_num>
<stlm_pos>2</stlm_pos>
<stlm_aantal>1.000000</stlm_aantal>
</stlm>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-101707</arti_code>
<stlm_num>3</stlm_num>
<stlm_pos>3</stlm_pos>
<stlm_aantal>5.000000</stlm_aantal>
</stlm>
</stlh>
しかし、私が必要としているのに戻ることができないのは
<stlh>
<admi_num>1</admi_num>
<stlh_num>3P-101707</stlh_num>
<stlh_oms_1>cover 1MF undercolumn</stlh_oms_1>
</stlh>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-2000242</arti_code>
<stlm_num>1</stlm_num>
<stlm_pos>1</stlm_pos>
<stlm_aantal>1.000000</stlm_aantal>
</stlm>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-2000243</arti_code>
<stlm_num>2</stlm_num>
<stlm_pos>2</stlm_pos>
<stlm_aantal>1.000000</stlm_aantal>
</stlm>
<!-- split into multiple row (result) here -->
<stlh>
<admi_num>1</admi_num>
<stlh_num>3P-2000245</stlh_num>
<stlh_oms_1>Cover 2 undercolum 1MF</stlh_oms_1>
</stlh>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-2000242</arti_code>
<stlm_num>1</stlm_num>
<stlm_pos>1</stlm_pos>
<stlm_aantal>1.000000</stlm_aantal>
</stlm>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-2000243</arti_code>
<stlm_num>2</stlm_num>
<stlm_pos>2</stlm_pos>
<stlm_aantal>1.000000</stlm_aantal>
</stlm>
<stlm>
<admi_num>1</admi_num>
<arti_code>3P-101707</arti_code>
<stlm_num>3</stlm_num>
<stlm_pos>3</stlm_pos>
<stlm_aantal>5.000000</stlm_aantal>
</stlm>
これを個別の XML ファイルに書き込む必要があります。stlh_num ごとに新しいファイルが必要です。
これは可能ですか?