首页 > 数据库技术 > 详细

分页SQL

时间:2015-03-19 00:44:10      阅读:367      评论:0      收藏:0      [点我收藏+]

USE [OumindBlog]
GO
/****** Object: StoredProcedure [dbo].[Usp_GetAlbByPage14] Script Date: 03/18/2015 23:37:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <JJH>
-- Create date: <Create Date,,>
-- Description: <得到相册分页数据>
-- =============================================
ALTER PROCEDURE [dbo].[Usp_GetAlbByPage14]
-- Add the parameters for the stored procedure here
@pageIndex int,
@pageSize int,
@rowCount int output
AS
BEGIN
--关闭sql语句的执行统计,提高性能
SET NOCOUNT ON;

--计算开始和结束的标签
declare @startIndex int,@endIndex int
set @startIndex =(@pageIndex-1)*@pageSize
set @endIndex=@pageIndex*@pageSize

--得到分页的数据
select * from (select rowId=(ROW_NUMBER() over(order by paid desc)),* from BlogPhotoAlblum where PaIsDel=0)
as t where t.rowId>@startIndex and t.rowId<=@endIndex

--获取数据总行数
select @rowCount=COUNT(1) from BlogPhotoAlblum where PaIsDel=0

END

分页SQL

原文:http://www.cnblogs.com/dianshen520/p/4349127.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!