CREATE PROCEDURE [dbo] [Pro_Pager]
@ PageSize NVARCHAR (20),
@ RowStart nvarchar (20),
@ SQLStr nvarchar (Max),
@ Orderby nvarchar (100)
AS
The BEGIN
DECLARE @ StrSQL NVARCHAR (Max)
The SET @ StrSQL='SELECT TOP + @ PageSize +' * FROM (SELECT ROW_NUMBER () OVER (ORDER BY '+ @ Orderby +) AS NUMBER, * FROM (' + @ SQLStr +) AS TableA) AS TableB WHERE TableB. NUMBER>' + @ RowStart + '
DECLARE @ StrCountSQL NVARCHAR (Max)
The SET @ StrCountSQL='SELECT COUNT (*) FROM (' + @ SQLStr +) AS TableC'
EXEC (@ StrSQL + @ StrCountSQL)
END