SELECT
[RowNum],
[AccountID], /* pk */
[CustomerID], /* fk */
[Name] AS [CustomerName], /* fk name column */
[DiscountAmount],
[DiscountRate],
[DiscountCode],
[Notes],
[CreatedDate],
[CreatedBy],
[ModifiedDate],
[ModifiedBy]
FROM
(
SELECT
[dbo].[Accounts].[AccountID], /* pk */
[dbo].[Accounts].[CustomerID], /* fk */
[dbo].[Customers].[Name] AS [CustomerName], /* fk name column */
[dbo].[Accounts].[DiscountAmount],
[dbo].[Accounts].[DiscountRate],
[dbo].[Accounts].[DiscountCode],
[dbo].[Accounts].[Notes],
[dbo].[Accounts].[CreatedDate],
[dbo].[Accounts].[CreatedBy],
[dbo].[Accounts].[ModifiedDate],
[dbo].[Accounts].[ModifiedBy]
,
ROW_NUMBER() OVER
(
ORDER BY
[dbo].[Accounts].[CreatedDate] DESC
) AS [RowNum]
FROM
[dbo].[Accounts]
INNER JOIN [dbo].[Customers] ON [dbo].[Accounts].[CustomerID] = [dbo].[Customers].[CustomerID]
WHERE
[dbo].[Accounts].[AccountID] = @AccountID
) AS [PagedSet]
WHERE
[RowNum] BETWEEN @StartRowIndex AND @EndRowIndex