Skip to main content

Posts

Showing posts with the label Sorting and Paging

Fast SQL Server Stored Procedure with Filtering, Sorting and Paging

OFFSET/FETCH Pagination:-  With the help of these OFFSET and FETCH keywords inside a CTE I managed to build a SQL Stored procedure that was at least twice as fast in return times as the other average ones found on the internet. Here I'm sharing 2 examples to achieving the SQL filtering, sorting and paging . Both example are tested and working fine but I will recommend example 1 for you. Example 1, --[dbo].[usp_GetemployeeCodes] NULL, 1, 10, 'employee_code', 'DESC' CREATE PROCEDURE [dbo] . [usp_GetEmployeeCodes] (     /* Optional Filters for Dynamic Search*/     @SearchCode NVARCHAR ( 50 ) = NULL,             /*– Pagination Parameters */             @PageNo INT = 1 ,             @PageSize INT = 15 ,    /*– Sorting Parameters */  ...