CREATE PROCEDURE [dbo].[GetVirtualListItems]
@StartIndex int,
@EndIndex int,
@SortColumn int,
@SortDirection int
AS
BEGIN
WITH SortedData AS
(
SELECT MyTable.Id,
MyTable.Firstname,
MyTable.Surname,
ROW_NUMBER() OVER(ORDER BY
CASE WHEN @SortColumn = 1 AND @SortDirection = 0 THEN Id END DESC,
CASE WHEN @SortColumn = 1 AND @SortDirection = 1 THEN Id END ASC,
CASE WHEN @SortColumn = 2 AND @SortDirection = 0 THEN Firstname END DESC,
CASE WHEN @SortColumn = 2 AND @SortDirection = 1 THEN Firstname END ASC,
CASE WHEN @SortColumn = 3 AND @SortDirection = 0 THEN Surname END DESC,
CASE WHEN @SortColumn = 3 AND @SortDirection = 1 THEN Surname END ASC
) AS 'RowNumber'
FROM MyTable
)
SELECT *
FROM SortedData
WHERE RowNumber BETWEEN @StartIndex AND @EndIndex
END
|