Eu tenho que criar um arquivo XML usando sql
<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>
Meu SQL é o seguinte
(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"
Minha saída vem como abaixo:
<externalCodes>
<externalCode>
<system>CALYPSO</system>
<extCode>Mon</extCode>
<system>CMS-GDP</system>
<extCode>Mon</extCode>
<system>MANUAL</system>
<extCode>Mon</extCode>
</externalCode>
</externalCodes>
Mas a saída esperada é como abaixo
<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>
Não tenho sua fonte de dados, então criei um cte com alguns registros nele
saída para ele: