У нас есть этот код:
SELECT
(SELECT
'infor' AS [Process/TenantID],
(SELECT
ROW_NUMBER() OVER(ORDER BY gld_serial_no ASC) as [@sequence],
(SELECT TOP (1)
'1' AS [DimensionCode/@sequence],
gld_dim1 AS [DimensionCode]
FROM
slr_gl_dta_paid
GROUP BY
gld_dim1
FOR XML PATH ('DimensionCode'), TYPE) AS [DimensionCodes]
FROM
slr_gl_dta_paid
FOR XML PATH ('JournalEntryLine'), TYPE) AS [SourceSystemJournalEntry]
FOR XML PATH ('DataArea'), type
)
FOR XML PATH (''), ROOT('ProcessSourceSystemJournalEntry')
Результат примерно такой:
<ProcessSourceSystemJournalEntry>
<DataArea>
<Process>
<TenantID>infor</TenantID>
</Process>
<SourceSystemJournalEntry>
<JournalEntryLine sequence="1">
<DimensionCodes>
<DimensionCode>
<DimensionCode sequence="1">CD53</DimensionCode>
</DimensionCode>
</DimensionCodes>
</JournalEntryLine>
<JournalEntryLine sequence="2">
<DimensionCodes>
<DimensionCode>
<DimensionCode sequence="1">CD99</DimensionCode>
</DimensionCode>
</DimensionCodes>
</JournalEntryLine>
</SourceSystemJournalEntry>
</DataArea>
</ProcessSourceSystemJournalEntry>
Но нам нужен результат, который будет таким:
<ProcessSourceSystemJournalEntry>
<DataArea>
<Process>
<TenantID>infor</TenantID>
</Process>
<SourceSystemJournalEntry>
<JournalEntryLine sequence="1">
<DimensionCodes>
<DimensionCode sequence="1">CD53</DimensionCode>
</DimensionCodes>
</JournalEntryLine>
<JournalEntryLine sequence="2">
<DimensionCodes>
<DimensionCode sequence="1">CD99</DimensionCode>
</DimensionCodes>
</JournalEntryLine>
</SourceSystemJournalEntry>
</DataArea>
</ProcessSourceSystemJournalEntry>
Как это можно сделать?