复制代码 代码如下:
DECLARE @InputId INT ;
SET @InputId=1;
param2为:@id=@InputId;
复制代码 代码如下:
ALTER PROCEDURE sp_pager
(
@TableName nvarchar(50), -- 表名
@ReturnFields nvarchar(200) = '*', -- 需要返回的列
@PageSize int = 50, -- 每页记录数
@PageIndex int = 1 -- 当前页码
)
AS
DECLARE @SQL NVARCHAR(1000)
DECLARE @paramters NVARCHAR(200)
BEGIN
SET NOCOUNT ON
SET @SQL='SELECT '+@ReturnFields+' FROM '+@TableName+' WHERE ID>(SELECT TOP 1 ID FROM (SELECT TOP '+CAST(@PageSize*@PageIndex AS VARCHAR)+' ID FROM '+@TableName+ ' ORDER BY ID )AS A ORDER BY ID DESC)'
PRINT @SQL
EXECUTE sp_executesql @SQL,@paramters,@columns=@ReturnFields
END
新闻热点
疑难解答