一个分页的存储过程

SET QUOTED_IDENTIFIER
ON
GO
SET ANSI_NULLS
ON
GO
create PROC FenYe
(
@sqlstr nvarchar(4000), --查询字符串
@pagecount int,--第N页
@pagesize int--每页行数
)
 AS
 set nocount on
declare
@P1 int,--P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount
output select @rowcount as 总行数,ceiling(1.0*@rowcount/@pagesize) as 页数,
@pagecount as 当前页 set @pagecount=(@pagecount-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@pagecount,@pagesize
exec sp_cursorclose @P1
GO
SET QUOTED_IDENTIFIER
OFF
GO
SET ANSI_NULLS
ON
GO

你可能感兴趣的:(Go)