USE [channel]
GO
/****** 对象: StoredProcedure [dbo].[mst_sp_pageshow_new] 脚本日期: 05/14/2010 16:10:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[mst_sp_pageshow_new]
@qCols varchar(1000), --需要查询的列
@qTables varchar(1000), --需要查询的表
@qWhere varchar(1000), --需要查询的条件
@iKey varchar (20), --标识字段
@oKey varchar(100), --排序字段
@pageSize int, --每页的行数
@pageNumber int --要显示的页码, 从0开始
AS
set nocount on
BEGIN
DECLARE @sqlText AS varchar(2500)
DECLARE @sqlTable AS varchar(2500)
SET @sqlTable = 'SELECT TOP ' + STR((@pageNumber + 1) * @pageSize) + ' ' + @iKey +' from '+ @qTables + ' where ' + @qWhere + ' order by '+@oKey
SET @sqlText =
'SELECT TOP ' + STR(@pageSize) + ' ' + @qCols +
' FROM ' + @qTables +
' WHERE ' + @iKey + ' NOT IN(SELECT TOP ' +
STR(@pageNumber * @pageSize) + ' ' + @iKey +
' FROM (' + @sqlTable + ') AS tableB) AND ' + @qWhere + ' order by '+@oKey
EXEC (@sqlText)
print(@sqltext)
END
分页存储过程
最新推荐文章于 2022-08-24 11:14:15 发布