使用下面的SQL查询我正在生成如下所示的XML文件。
SELECT CAST((SELECT
(
SELECT
ICase,
DPCRef
FROM
#HD HD WHERE HD.OrdRef=PICK.OrdRef
GROUP BY
ICase,
DPCRef
FOR XML PATH('HD'), TYPE
),
(
SELECT
PCode,
SOLnNt,
(
SELECT SSCCRef
FROM #SSCC LM
WHERE LD.OrdRef = LM.OrdRef AND LD.PCode=LM.PCode
GROUP BY
SSCCRef
FOR XML PATH(''), ROOT('SSCC'), TYPE
)
FROM #LD LD
WHERE LD.OrdRef = PICK.OrdRef
GROUP BY
PCode,
SOLnNt
FOR XML PATH('LD'), TYPE
)
FROM #PICK PICK
GROUP BY OrdRef
FOR XML PATH('PICK'), ROOT('PickOrder')) AS XML) AS OrdersPickingConfirmationXML
结果:
<PICK>
<HD>
<CustCode>PAV001</CustCode>
<OrdRef>813804</OrdRef>
</HD>
<LD>
<PCode>PROD0001</PCode>
<Rotation>14/D004193</Rotation>
<SSCC>
<SSCCRef>TEST 1</SSCCRef>
<SSCCRef>TEST1</SSCCRef>
</SSCC>
</LD>
</PICK>
有时候#SSCC表中没有数据。那时SSCC标签没有显示在XML中。如果没有数据,我需要将其显示为</SSCC>
。无论如何,我可以得到空白标签</SSCC>