Try the following:
SELECT
@myXml.value('(/Cust/@id)[1]', 'int') AS '@id',
@myXml.query('/node()[1]/node()')
FOR XML PATH('Customer')
Gives me the conclusion:
<Customer id="1">
<Name>aaaaaaaaaa</Name>
<Desc>bbbbbbbbbb</Desc>
</Customer>
With the help of FOR XML PATHyou can quite easily "restore" this attribute, which will be lost during the conversion.
source
share