公用分页查询的存储过程

1,sql存储过程

ALTER PROCEDURE [dbo].[Proc_GetProduceDispatch]
@SqlStr    NVARCHAR(4000), --查询字符串 
@PageIndex    INT,        --第N页 
@PageSize      INT --每页行数
 AS

DECLARE @RecordCount int,@P1 INT
 
IF @PageIndex <1 SET @PageIndex = 1
SET @PageIndex = (@PageIndex-1) * @PageSize + 1
 
EXEC sp_cursoropen @P1 OUTPUT, @SqlStr, @scrollopt = 1, @ccopt = 335873, @rowcount = @RecordCount OUTPUT
 
IF (@P1 != 0)
BEGIN
  EXEC sp_cursorfetch @P1, 16, @PageIndex, @PageSize
  EXEC sp_cursorclose @P1
END

SELECT @RecordCount

2,

posted @ 2013-08-09 11:37  namehwh  阅读(119)  评论(0编辑  收藏  举报