Trying to create a Stored procedure that will give the required no. of records and also the total no. of records in that table.
The '@Query' part gives result when I execute it separately. So there's no problem with that.
Could Someone please check if the syntax is correct, cause I'm not getting at any output
ALTER PROCEDURE GetRecordsByPage
(
@TableName nvarchar(50),
@ColumnName nvarchar(50),
@OrderByClause nvarchar(50),
@StartIndex nvarchar(50),
@EndIndex nvarchar(50),
@TotalRows nvarchar(50) output
)
AS
BEGIN
DECLARE @Query nvarchar(max)
select @TotalRows = 'select count(*) from '+@TableName+' where deleted=0'
select @Query = 'with temp as (select row_number() over (order by '+
@colname+' '+@OrderByClause+') as row, * from '+@tablename+')
select * from temp where row between '+@startIndex+' and '+@EndIndex
execute sp_executesql @Query, @TotalRows output
END
-- execute GetRecordsByPage 'tblBranch','BranchName', '2', '10'