ALTER PROC [dbo].[GetPagedDataForNotity]
(
@StartRowIndex INT,
@MaximumRows INT,
@Order VARCHAR(50),
@WHERE NVARCHAR(300)
)
AS
DECLARE @SQL NVARCHAR(MAX)
SET @SQL='WITH OrdersDatas AS(select id,ROW_NUMBER() over (order by '+@Order+') as rownumber from T_Notity '+@WHERE+' )
select T_Notity.*,(SELECT COUNT(1) FROM OrdersDatas) as counts
From OrdersDatas inner join T_Notity on OrdersDatas.id=T_Notity.id
where rownumber BETWEEN (@StartRowIndex+1) AND (@MaximumRows+@StartRowIndex) Order By rownumber ASC'
EXECUTE sp_executesql @SQL,N'@Order varchar(50),@where nvarchar(400),@MaximumRows int,@StartRowIndex int',@Order,@WHERE,@MaximumRows,@StartRowIndex