以前写的一个分页存储过程,刚才不小心翻出来(3)
Response.Write("没有记录")
ELSE
GetRecord=RS.GetRows(IntPageSize)
For i=0 To Ubound(GetRecord,2)
Response.Write(GetRecord(0,i),GetRecord(1,i),GetRecord(2,i)) '...输出内容
NEXT
GetRecord=Null
END IF
SET RS=NOTHING
有用的朋友请自己慢慢调试吧,总记录是用ASP来取的,存储在SESSION里边,如果每次都统计一次总记录,将会非常费时,当然,如果你想在存储过程里来取总记录和总页数然后返回也是可以的,下边是代码:
--获取记录总数--
SET @tmpSQL='SELECT @getRecordCounts=COUNT('+@strKeyField+') FROM '+@strTable+@tmpWhere
EXEC sp_executesql @tmpSQL,N'@getRecordCounts int output',@getRecordCounts OUTPUT
--获取总页数--
SET @tempFolatNumber=@getRecordCounts%@IntPageSize
IF @getRecordCounts<=@IntPageSize
SET @getPageCounts=1
ELSE
BEGIN
IF @tempFolatNumber != 0
SET @getPageCounts=(@getRecordCounts/@IntPageSize)+1
ELSE
SET @getPageCounts=(@getRecordCounts/@IntPageSize)
END
SET @tmpSQL='SELECT @getRecordCounts=COUNT('+@strKeyField+') FROM '+@strTable+@tmpWhere
EXEC sp_executesql @tmpSQL,N'@getRecordCounts int output',@getRecordCounts OUTPUT
--获取总页数--
SET @tempFolatNumber=@getRecordCounts%@IntPageSize
IF @getRecordCounts<=@IntPageSize
SET @getPageCounts=1
ELSE
BEGIN
IF @tempFolatNumber != 0
SET @getPageCounts=(@getRecordCounts/@IntPageSize)+1
ELSE
SET @getPageCounts=(@getRecordCounts/@IntPageSize)
END
别忘了返回定义参数:
@getRecordCounts int output,--返回总记录
@getPageCounts int output--返回总页数