分页

来源:互联网 发布:vue.js 数据绑定 编辑:程序博客网 时间:2024/05/01 23:52

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  munaiwu
-- Create date: 20091030
-- Description: 公文分页存储过程
-- =============================================
CREATE PROCEDURE pagination1
 -- Add the parameters for the stored procedure here
 @pagesize int, --页面大小,如每页存储20条记录
 @pageindex int  ---当前页号
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON; --不返回计数,不返回任何结果集

    -- Insert statements for procedure here
 declare @indextable table(id int identity(1,1),nid int) --表变量
 declare @PageLowerBound int --定义页面底码
 declare @PageUpperBound int --定义页面顶码
 
 set @PageLowerBound = (@pageindex - 1)* @pagesize
 set @PageUpperBound = @PageLowerBound + @pagesize
 set rowcount @PageUpperBound --在达到指定的行数后停止处理
 insert into @indextable(nid) select gid from TGongwen where fariqi > dateadd(day,-365,getdate()) order by fariqi desc

  select O.gid,O.mid,O.title,O.fadanwei,O.fariqi from TGongwen as O, @indextable as t where O.gid=t.nid and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
END
set nocount off --返回计数,返回任何结果集
GO

原创粉丝点击