Here is the store procedure by which you can fetch your require data with paging and filter you need
Paging Logic
Filter between two dates in SQL
Paging Logic
--EXEC dbo.[Demo_Paging_Logic] 1,10,'LookupValue ASC','LookupValue like''%123%'' CREATE PROCEDURE dbo.[Demo_Paging_Logic] @PageNumber INT = 1 ,@PageSize INT = 5 ,@SortExpression NVARCHAR(20) = 'LookupValue DESC' ,@WhereCondition NVARCHAR(MAX) = ' 1=1 ' AS BEGIN SET NOCOUNT ON; DECLARE @FirstRec INT ,@LastRec INT ,@TotalRows INT SET @FirstRec = (@PageNumber - 1) * @PageSize SET @LastRec = (@PageNumber * @PageSize + 1) SET @TotalRows = @FirstRec - @LastRec + 1 DECLARE @SortExpression1 NVARCHAR(MAX) DECLARE @Query NVARCHAR(MAX) DECLARE @Query1 NVARCHAR(MAX) SET @Query = 'SELECT * FROM(SELECT Cast(ROW_NUMBER() OVER (ORDER BY ' + @SortExpression + ') As int) AS ROWNUM, COUNT(*) OVER(PARTITION BY 1) TotalRecord,* FROM Master.tblLookupValues WHERE ' + @WhereCondition + ') AS tbl WHERE ROWNUM > ' + CONVERT(NVARCHAR(10), @FirstRec) + ' AND ROWNUM < ' + CONVERT(NVARCHAR(10), @LastRec) + ' ORDER BY ROWNUM ASC' PRINT @Query EXEC sp_Executesql @Query END GO
Filter between two dates in SQL
DECLARE @StartDate AS VARCHAR(10) = '10-03-2014' DECLARE @EndDate AS VARCHAR(10) = '26-03-2014' SELECT * FROM tABLE WHERE Cast(convert(DATETIME, Cast(CreatedDate AS DATETIME), 103) AS DATE) BETWEEN Cast(convert(DATETIME, @StartDate, 103) AS DATE) AND Cast(convert(DATETIME, @EndDate, 103) AS DATE)
No comments:
Post a Comment