sql server定义存储过程

来源:互联网 发布:张靓颖 结婚 知乎 编辑:程序博客网 时间:2024/06/09 14:28
 

-- ================================================
-- 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:  <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE 定义储存名
 @pageSize int,  --每页记录数量
 @pageCount int output,  --总页数
 @pageIndex int  --当前页索引号

AS
BEGIN
declare @totalRecords int
select @totalRecords = count(id) from 视图或者表名
if(@totalRecords % @pageSize = 0)
 set @pageCount = @totalRecords / @pageSize;
else
 set @pageCount = @totalRecords / @pageSize +1;
with temp as (select row_number() over (order by id) as sid,* from 视图或者表名)
select * from temp where sid between (@pageIndex -1)*@pageSize +1 and @pageIndex * @pageSize
return @totalRecords
end