在线等一个ASP与存储过程分页问题
存储过程代码如下:
CREATE PROCEDURE haocai_product_searchpage
(
@strTblName VARCHAR(8000), --表名或视图表
@strFields VARCHAR(8000) = '* ', --欲选择字段列表
@strOrdField VARCHAR(100), --排序字段
@strOrdField2 VARCHAR(100), --排序字段 2
@strKeyField VARCHAR(100), --主键
@intPageNo INT= 0, --页号,从0开始
@intPageSize INT= 10, --页尺寸
@strWhere VARCHAR(4000)= ' ', --条件
@bitOrdType BIT= 1 --排序,1=降序,0=升序
)
AS
SET NOCOUNT ON
DECLARE @strSQL VARCHAR(8000)
IF @intPageNo = 0
BEGIN
SET @strSQL = 'SELECT TOP ' + CAST(@intPageSize AS VARCHAR) + ' ' + @strFields + ' FROM ' + @strTblName
IF @strWhere != ' '
SET @strSQL = @strSQL + ' WHERE ' + @strWhere
IF @bitOrdType = 1
SET @strSQL = @strSQL + ' ORDER BY ' + @strOrdField + ' DESC '
ELSE
SET @strSQL = @strSQL + ' ORDER BY ' + @strOrdField + ' ASC '
END
ELSE
BEGIN
SET @strSQL = 'DECLARE @intCurPageNo int; '
SET @strSQL = @strSQL + 'DECLARE @intNextPageNo int; '
SET @strSQL = @strSQL + 'SET @intCurPageNo = ' + CAST(@intPageNo AS VARCHAR) + '* ' + CAST(@intPageSize AS VARCHAR) + '; '
SET @strSQL = @strSQL + 'SET @intNextPageNo = ' + CAST(@intPageNo+1 AS VARCHAR) + '* ' + CAST(@intPageSize AS VARCHAR) + '; '
SET @strSQL = @strSQL + 'DECLARE @strSQL VARCHAR(8000); '
IF @bitOrdType = 1
BEGIN
SET @strSQL = @strSQL + 'SET @strSQL = ' 'SELECT ' + @strFields + ' FROM (SELECT TOP 4 * FROM ' + @strTblName
IF @strWhere != ' '
SET @strSQL = @strSQL + ' WHERE ' + @strWhere
SET @strSQL = @strSQL + ' ORDER BY ' + @strOrdField + ' DESC) AS atmp WHERE ' + @strKeyField
+ ' NOT IN (SELECT TOP 2 ' + @strKeyField + ' FROM ' + @strTblName
IF @strWhere != ' '
SET @strSQL = @strSQL + ' WHERE ' + @strWhere
SET @strSQL = @strSQL + ' ORDER BY ' + @strOrdField + ' DESC) ORDER BY