打印本文 打印本文  关闭窗口 关闭窗口
实现分页的例子-使用存储过程来实现分页
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005/9/10 13:48:34
在  网上 讨论 如何 实现 分页  有很多程序,我在这里向大家  介绍一种实现分页的新的方法,使用 存储过程 来实现分页
   由于 这段程序写的 比较早,那个时候 还没有 SQL 7,每一个 Varchar 只能 支持 255 个字符,所以 采取了一种比较笨的办法,如果大家有兴趣,请去  http://www.chinaasp.com/sqlbbs/default.asp 的数据库论坛发表意见,我会看情况,决定是否将这个 存储过程修改成为SQL 7 的存储过程;
   并在此起到 一个 抛砖引玉  的 作用
   这个 程序只能  达到  10 个 分页
if exists (select * from sysobjects where id = object_id('dbo.sp_productPage') and sysstat & 0xf = 4)
    drop procedure dbo.sp_productPage
GO

CREATE PROCEDURE sp_productPage
@intStart TINYINT=1,
@intEnd TINYINT=10
with ENCRYPTION
AS
  Declare @strProductID VARCHAR(8),@strProductName VARCHAR(20),
  @strSQL1 VARCHAR(100),
  @strSQL2 VARCHAR(100),
  @strSQL3 VARCHAR(100),
  @strSQL4 VARCHAR(100),
  @strSQL5 VARCHAR(100),
  @strSQL6 VARCHAR(100),
  @strSQL7 VARCHAR(100),
  @strSQL8 VARCHAR(100),
  @strSQL9 VARCHAR(100),
  @strSQL10 VARCHAR(100),
  @intCCount TINYINT,
  @intCount TINYINT,
  @i TINYINT
  select @i=1
  Declare cur_Product SCROLL CURSOR For
   Select ProductID,ProductName from KF_Product order by ProductID
   Select @intCCount=count(productId) From KF_Product
  open cur_Product
  Fetch ABSOLUTE @intStart From cur_Product Into @strProductID,@strProductName
  if @@FETCH_STATUS=0
    Select @intCount=@intStart
  Fetch cur_Product Into @strProductID,@strProductName
  if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL1='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount) +' Union '
       End
   else
    Begin
       Select @strSQL1='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
    End
  Fetch cur_Product Into @strProductID,@strProductName
  if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL2='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
       Begin
          Select @strSQL2='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
          Goto EndPro
       End
    Fetch cur_Product Into @strProductID,@strProductName
    if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL3='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL3='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
      End
  Fetch cur_Product Into @strProductID,@strProductName
if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL4='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL4='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
      End
  Fetch cur_Product Into @strProductID,@strProductName
if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL5='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL5='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
      End
   Fetch cur_Product Into @strProductID,@strProductName
  if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL6='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL6='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
      End
  Fetch cur_Product Into @strProductID,@strProductName
  if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL7='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL7='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
      End
  Fetch cur_Product Into @strProductID,@strProductName
if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL8='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
       Select @strSQL8='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intcCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)
       Goto EndPro
      End
  Fetch cur_Product Into @strProductID,@strProductName
if @@FETCH_STATUS=0
       Begin
         Select @intCount=@intCount+1
         Select @strSQL9='Select productId='' + @strProductID + '',productName='' + @strProductName+ '',ProductCount=' + convert(VARCHAR,@intCount)+',ProductSumCount='+ convert(VARCHAR,@intCCount)+' Union '
       End
    else
      Begin
    &nb

[1] [2]  下一页



打印本文 打印本文  关闭窗口 关闭窗口