1DECLARE @PageNumber AS INT
2DECLARE @RowsOfPage AS INT
3DECLARE @SortingCol AS VARCHAR(100) ='FruitName'
4DECLARE @SortType AS VARCHAR(100) = 'DESC'
5SET @PageNumber=1
6SET @RowsOfPage=4
7SELECT FruitName,Price FROM SampleFruits
8ORDER BY
9CASE WHEN @SortingCol = 'Price' AND @SortType ='ASC' THEN Price END ,
10CASE WHEN @SortingCol = 'Price' AND @SortType ='DESC' THEN Price END DESC,
11CASE WHEN @SortingCol = 'FruitName' AND @SortType ='ASC' THEN FruitName END ,
12CASE WHEN @SortingCol = 'FruitName' AND @SortType ='DESC' THEN FruitName END DESC
13OFFSET (@PageNumber-1)*@RowsOfPage ROWS
14FETCH NEXT @RowsOfPage ROWS ONLY