1、CREATE PROCEDURE GetProductsPaged
@lastProductID int,
@pageSize int
AS
SET ROWCOUNT @pageSize
SELECT *
FROM Products
WHERE [standard search criteria]
AND ProductID > @lastProductID
ORDER BY [Criteria that leaves ProductID monotonically increasing]
GO2、死琐

解决方案 »

  1.   

    1.
    /*
    用存储过程实现的分页程序
    */
    CREATE procedure Department_pagination 
    @SelectStr nvarchar(1000),
    @ColumnStr nvarchar (1000),
    @OrderStr nvarchar (1000),
    @CurrentPage int,
    @PageCount int
    as
    declare @TimeName nvarchar(25)
    declare @TableStr nvarchar(1000)select @TimeName = convert(nvarchar(23), getdate(), 121)
    set @TimeName = REPLACE(@TimeName, '.', '')
    set @TimeName = REPLACE(@TimeName, ':', '')
    set @TimeName = REPLACE(@TimeName, '-', '')
    set @TimeName = REPLACE(@TimeName, ' ', '')select @TableStr='create table ##Tab' + @TimeName + '(wb int identity,'
    exec(@TableStr+@ColumnStr+')')
    exec('insert into ##Tab' + @TimeName + ' ' + @SelectStr + ' order by ' + @OrderStr)
    exec('select * from ##Tab' + @TimeName + ' where wb between ((' + @CurrentPage + '-1)*' + @PageCount + '+1) and ' + @CurrentPage + '*' + @PageCount + ' order by wb')
    exec('drop table ##Tab' + @TimeName)
    GO参数1:select语句。2:字段列表。3:排序字段。4:当前页。5每页数目
    2.事务应尽可能的短,较长的事务增加了用户不能访问锁定数据的可能性
      

  2.   

    1.补充:
    必须要有行标识列:
    建议自动号!
    不建议使用 recordset 的客户端分页功能(pagesize,pages)!2.分解成小事务!