SQL SERVER 2005 分页存储过程

前端之家收集整理的这篇文章主要介绍了SQL SERVER 2005 分页存储过程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

  项目介绍: 评论分页存储过程

  项目背景:asp.net(c#) +sql2005

  存储过程代码

以下为引用的内容
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: zhaoyang
-- Create date: 2009-8-21
-- Description: 显示用户评论列表
-- =============================================
CREATE PROCEDURE [dbo].[CommentShowList_zy]
@GeneralID int,--信息ID
@ParentID int,--父ID
@OrderFlag int,--排序标示 0标示最新 1标示热门
@CurrentPage int,--当前页码
@pagesize int --每页的数据条数
AS
BEGIN
IF(@ParentID=0) --读取评论内容
BEGIN
IF(@OrderFlag=0)
BEGIN
with a as(
select *,px=row_number() over(order by id desc) from cms_wangpiao.dbo.Comment_zy where GeneralID=@GeneralID and ParentID=@ParentID
)
select * from a where px BETWEEN(@CurrentPage-1)* @pagesize+1 and @CurrentPage* @pagesize
END
IF(@OrderFlag=1)
BEGIN
with b as(
select *,px=row_number() over(order by a.CountReply desc ) from (
select *,(select count(0) from Comment_zy czb where czb.ParentID=cza.id) as CountReply from Comment_zy cza where GeneralID=@GeneralID and ParentID=@ParentID ) a
)
select * from b where px BETWEEN (@CurrentPage-1)* @pagesize+1 and @CurrentPage* @pagesize
END
END
ELSE--读取评论回复内容
BEGIN
select * from cms_wangpiao.dbo.Comment_zy where ParentID=@ParentID ORDER BY id desc
END
END

  来自:http://www.cnblogs.com/studyplay/

猜你在找的MsSQL相关文章