|
发表于 2020-8-9 10:45:01
|
显示全部楼层
CREATE PROCEDURE SplitPage
@SQL VARCHAR(400),
@Page int,
@RecsPerPage int,
@ID VARCHAR(255),
@Sort VARCHAR(255),
@where VARCHAR (255)
AS
DECLARE @Str nVARCHAR(4000)
SET @Str='SELECT TOP '+CAST(@RecsPerPage AS VARCHAR(20))+' * FROM '+@SQL+' WHERE '+@where +' and '+@ID+' NOT IN (SELECT TOP '+CAST((@RecsPerPage*(@Page-1)) AS VARCHAR(20))+' '+@ID+' FROM '+@SQL+' where '+@where+' ORDER BY '+@Sort+') ORDER BY '+@Sort
PRINT @Str EXEC sp_ExecuteSql @Str
GO |
|