Answers for "sql query with pagination examples"

SQL
3

sql server pagination

SELECT col1, col2, ...
 FROM ...
 WHERE ... 
 ORDER BY -- this is a MUST there must be ORDER BY statement
-- the paging comes here
OFFSET     10 ROWS       -- skip 10 rows
FETCH NEXT 10 ROWS ONLY; -- take 10 rows
Posted by: Guest on May-21-2020
0

how to pagination in sql - dynamic pagination

DECLARE @PageNumber AS INT
DECLARE @RowsOfPage AS INT
DECLARE @SortingCol AS VARCHAR(100) ='FruitName'
DECLARE @SortType AS VARCHAR(100) = 'DESC'
SET @PageNumber=1
SET @RowsOfPage=4
SELECT FruitName,Price FROM SampleFruits
ORDER BY 
CASE WHEN @SortingCol = 'Price' AND @SortType ='ASC' THEN Price END ,
CASE WHEN @SortingCol = 'Price' AND @SortType ='DESC' THEN Price END DESC,
CASE WHEN @SortingCol = 'FruitName' AND @SortType ='ASC' THEN FruitName END ,
CASE WHEN @SortingCol = 'FruitName' AND @SortType ='DESC' THEN FruitName END DESC
OFFSET (@PageNumber-1)*@RowsOfPage ROWS
FETCH NEXT @RowsOfPage ROWS ONLY
Posted by: Guest on September-27-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language