Я выполняю следующий запрос
SELECT
ROW_NUMBER() OVER(ORDER BY [TransactionValues].[ID]) AS idx,
[Transactions].[ID] AS [id],
[Transactions].[EncryptedAccountID] AS [encryptedAccountID],
[Transactions].[Uploaded] AS [uploaded],
[Transactions].[Visible] AS [visible],
[Fields].[ID] AS [fieldId],
[Fields].[FriendlyName] AS [friendlyName],
[Fields].[OfficialName] AS [officialName],
[Fields].[Order] AS [order],
[Fields].[Visible] AS [valueVisible],
[TransactionValues].[ID] AS [valueId],
[TransactionValues].[FieldID] AS [valueFieldId],
[TransactionValues].[FriendlyValue] AS [friendlyValue],
[TransactionValues].[OfficialValue] AS [officialValue],
[TransactionValues].[TransactionID] AS [transactionId]
FROM
[Transactions]
INNER JOIN [TransactionValues]
ON [TransactionValues].[TransactionID] = [Transactions].[ID]
INNER JOIN [Fields]
ON [TransactionValues].[FieldID] = [Fields].[ID]
WHERE
[Transactions].[EncryptedAccountID] = @encryptedAccountID
FOR XML AUTO, ROOT('root')
, который возвращает XML в следующем формате (я пропустил возвращенные значения атрибута - они не уместны):
<root>
<Transactions idx="" id="" encryptedAccountID="" uploaded="" visible="">
<Fields id="" friendlyName="" officialName="" order="" visible="">
<TransactionValues valueId="" valueFieldId="" friendlyValue="" officialValue="" transactionId="" />
</Fields>
<Fields id="" friendlyName="" officialName="" order="" visible="">
<TransactionValues valueId="" valueFieldId="" friendlyValue="" officialValue="" transactionId="" />
</Fields>
</Transactions>
<Transactions idx="" id="" encryptedAccountID="" uploaded="" visible="">
<Fields id="" friendlyName="" officialName="" order="" visible="">
<TransactionValues valueId="" valueFieldId="" friendlyValue="" officialValue="" transactionId="" />
</Fields>
<Fields id="" friendlyName="" officialName="" order="" visible="">
<TransactionValues valueId="" valueFieldId="" friendlyValue="" officialValue="" transactionId="" />
</Fields>
</Transactions>
</root>
Пока все хорошо.
Теперь я хочу разбить результаты на страницы.Часть этого требует, чтобы вышеуказанный запрос выполнялся как подзапрос.Итак, теперь у меня есть следующий запрос:
SELECT
*
FROM
(
SELECT
ROW_NUMBER() OVER(ORDER BY [TransactionValues].[ID]) AS idx,
[Transactions].[ID] AS [id],
[Transactions].[EncryptedAccountID] AS [encryptedAccountID],
[Transactions].[Uploaded] AS [uploaded],
[Transactions].[Visible] AS [visible],
[Fields].[ID] AS [fieldId],
[Fields].[FriendlyName] AS [friendlyName],
[Fields].[OfficialName] AS [officialName],
[Fields].[Order] AS [order],
[Fields].[Visible] AS [valueVisible],
[TransactionValues].[ID] AS [valueId],
[TransactionValues].[FieldID] AS [valueFieldId],
[TransactionValues].[FriendlyValue] AS [friendlyValue],
[TransactionValues].[OfficialValue] AS [officialValue],
[TransactionValues].[TransactionID] AS [transactionId]
FROM
[Transactions]
INNER JOIN [TransactionValues]
ON [TransactionValues].[TransactionID] = [Transactions].[ID]
INNER JOIN [Fields]
ON [TransactionValues].[FieldID] = .[Fields].[ID]
WHERE
[Transactions].[EncryptedAccountID] = @encryptedAccountID
) AS [TransactionInfo]
WHERE
idx > 5
AND
idx <= 20
ORDER BY
[id], [order] ASC
FOR XML AUTO, ROOT('root')
Однако, это возвращает следующий XML
<root>
<TransactionInfo idx="" id="" encryptedAccountID="" uploaded="" visible="" fieldId="" friendlyName="" officialName="" order="" valueVisible="" valueId="" valueFieldId="" friendlyValue="" officialValue="" transactionId="" />
<TransactionInfo idx="" id="" encryptedAccountID="" uploaded="" visible="" fieldId="" friendlyName="" officialName="" order="" valueVisible="" valueId="" valueFieldId="" friendlyValue="" officialValue="" transactionId="" />
</root>
Вы можете видеть, что введение подзапроса вызвало предложение FOR XMLбольше не вкладывать дочерние результаты ... но я не понимаю, почему.
Может кто-нибудь сказать мне, как я могу реализовать разбиение на страницы с помощью ROW_NUMBER (), и результаты будут отформатированы как первый блок XMLвыше