我必须使用 sql 创建一个 XML 文件
<externalCodes>
<externalCode>
<system>CALYPSO</system>
<extCode>cptname</extCode>
</externalCode>
<externalCode>
<system>CMS-GDP</system>
<extCode>cptname</extCode>
</externalCode>
<externalCode>
<system>Manual</system>
<extCode>cptname</extCode>
</externalCode>
我的SQL如下
(SELECT system, extCode from(Select 'CALYPSO' AS 'system', LTRIM(RTRIM(c1.cptname)) AS 'extCode') a
FOR XML PATH(''), TYPE, ELEMENTS) AS "externalCodes/externalCode",
(SELECT system, extCode from(Select 'CMS-GDP' AS 'system', LTRIM(RTRIM(c1.cptname)) AS 'extCode') b
FOR XML PATH(''), TYPE, ELEMENTS) AS "externalCodes/externalCode",
(SELECT system, extCode from( Select 'MANUAL' AS 'system', LTRIM(RTRIM(c1.cptname)) AS 'extCode') c
FOR XML PATH(''), TYPE, ELEMENTS) AS "externalCodes/externalCode"
我的输出如下:
<externalCodes>
<externalCode>
<system>CALYPSO</system>
<extCode>Mon</extCode>
<system>CMS-GDP</system>
<extCode>Mon</extCode>
<system>MANUAL</system>
<extCode>Mon</extCode>
</externalCode>
</externalCodes>
但预期的输出如下
<externalCodes>
<externalCode>
<system>CALYPSO</system>
<extCode>Mon</extCode>
</externalCode>
<externalCode>
<system>CMS-GDP</system>
<extCode>Mon</extCode>
</externalCode>
<externalCode>
<system>MANUAL</system>
<extCode>Mon</extCode>
</externalCode>
</externalCodes>
我没有你的数据源,所以我创建了一个包含一些记录的 cte
输出: