sql2005分页存储过程-原创
2009-09-11 15:21 zhaoyang 阅读(296) 评论(0) 编辑 收藏 举报
项目介绍: 评论分页存储过程
项目背景: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
项目背景: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