寒冷的冰专栏

用代码书写人生

用户操作
[即时聊天] [发私信] [加为好友]
寒冷的冰ID:coldice
4550次访问,排名19691(1),好友0人,关注者1人。
coldice的文章
原创 4 篇
翻译 0 篇
转载 1 篇
评论 24 篇
最近评论
文章分类
收藏
    相册
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 一个分页存储过程收藏

    新一篇: 给自己的Blog 上添加定制的搜索引擎  | 

    来源:http://dotnet.mblogger.cn/zzjjmm/posts/1603.aspx

    CREATE PROCEDURE dbo.PostGetPostByPage

     (
      @page int,
      @forumid int,
      @topornot int
     )

    AS
     /* SET NOCOUNT ON */
     declare @begin int,@end int,@f int,@l int,@count int,@top int
     
     select @top=count(*) from Posts as p1 where p1.PostID=(select min(PostID) from Posts as p2 where p1.ThreadID=p2.ThreadID)
     and p1.ForumID=@forumid and PostType=4
     
     if @topornot=1
     
     select p1.PostType,p1.Title,p1.UserName,p1.TotalViews,p1.PostID,p1.ThreadID,p1.ForumID,FileName,
     Reply=(select Count(*) from Posts as p2 where p1.ThreadID=p2.ThreadID)-1,
     LastDate=(select Max(PostDate)from Posts as p2 where p1.ThreadID=p2.ThreadID),
     LastWriter=(select UserName from posts as p2 where p2.PostID=(select Max(PostID)from Posts as p2 where p1.ThreadID=p2.ThreadID))
     from Posts as p1 where p1.PostID=(select min(PostID) from Posts as p2 where p1.ThreadID=p2.ThreadID)
     and p1.ForumID=@forumid and PostType=4
     
     else if @topornot=2
     begin
     
     select @count=count(*) from Posts as p1 where p1.PostID=(select min(PostID) from Posts as p2 where p1.ThreadID=p2.ThreadID)
     and p1.ForumID=@forumid and PostType<>4
     
     declare my_cursor SCROLL CURSOR for
     select p1.PostID from Posts as p1 where p1.PostID=(select min(PostID) from Posts as p2 where p1.ThreadID=p2.ThreadID)
     and p1.ForumID=@forumid and PostType<>4 order by (select max(PostID) from Posts as p2 where p1.ThreadID=p2.ThreadID) desc
     open my_cursor
     
     
     
     if @count+@top<25 and @page=1
     begin
     select @f=1
     select @l=@count
     end
     if @count+@top>=25 and @page=1
     begin
     select @f=1
     select @l=25-@top
     end
     
     if(@page*25-@top>@count) and @page>1
     begin
     select @f=(@page-1)*25+1-@top
     select @l=@count
     end
     if(@page*25-@top<=@count) and @page>1
     begin
     select @f=(@page-1)*25+1-@top
     select @l=@page*25-@top
     end
     
     
     fetch absolute @f from my_cursor into @begin
     fetch absolute @l from my_cursor into @end
     set nocount off
      
     select p1.PostType,p1.Title,p1.UserName,p1.TotalViews,p1.PostID,p1.ThreadID,p1.ForumID,FileName,
     Reply=(select Count(*) from Posts as p2 where p1.ThreadID=p2.ThreadID)-1,
     LastDate=(select Max(PostDate)from Posts as p2 where p1.ThreadID=p2.ThreadID),
     LastWriter=(select UserName from posts as p2 where p2.PostID=(select Max(PostID)from Posts as p2 where p1.ThreadID=p2.ThreadID))
     from Posts as p1 where p1.PostID=(select min(PostID) from Posts as p2 where p1.ThreadID=p2.ThreadID)
     and p1.ForumID=@forumid and PostID<=@begin and PostID>=@end and PostType<>4 order by (select max(PostID) from Posts as p2 where p1.ThreadID=p2.ThreadID) desc
     
     close my_cursor
     end
     RETURN @@Rowcount

    GO

    发表于 @ 2004年07月09日 15:56:00|评论(loading...)|编辑

    新一篇: 给自己的Blog 上添加定制的搜索引擎  | 

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 寒冷的冰