How to create XML file by SQL query?
I don't have your data source, so I created a cte with some records in it

;with cte
AS 
(
       Select 'CALYPSO' AS 'system', 'Mon' as cptname
       union all Select 'CMS-GDP' , 'Mon'
       union all Select 'MANUAL' , 'Mon'
)
SELECT system, cptname as extCode
from 
   cte
FOR XML PATH('externalCode'), TYPE, ELEMENTS ,ROOT('externalCodes')


output for it:

&lt;externalCodes&gt;
   &lt;externalCode&gt;
      &lt;system&gt;CALYPSO&lt;/system&gt;
      &lt;extCode&gt;Mon&lt;/extCode&gt;
   &lt;/externalCode&gt;
   &lt;externalCode&gt;
      &lt;system&gt;CMS-GDP&lt;/system&gt;
      &lt;extCode&gt;Mon&lt;/extCode&gt;
   &lt;/externalCode&gt;
   &lt;externalCode&gt;
      &lt;system&gt;MANUAL&lt;/system&gt;
      &lt;extCode&gt;Mon&lt;/extCode&gt;
   &lt;/externalCode&gt;
&lt;/externalCodes&gt;