首页 > 其他 > 详细

查看文章的上一篇下一篇的逻辑总结

时间:2014-01-21 19:13:03      阅读:425      评论:0      收藏:0      [点我收藏+]

1、在同一类别下,根据当前文章ID查出小于当前文章的ID的最大文章ID。为上一篇。

2、在同一类别下,根据当前文章ID查出大于当前文章的ID的最小文章ID。为下一篇。

3、根据上一篇的文章ID,下一篇的文章ID,查出上一篇文章的标题,下一篇文章的标题。

4、最好把变量查出来,返回给程序。

create procedure [dbo].[spNews_S_NewsPrevNext]
@NewsID int,
@topid int
as
declare @Prev int
declare @Next int
declare @PrevTitle nvarchar(200)
declare @NextTitle nvarchar(200)
declare @PrevCategoryContent nvarchar(200)
declare @NextCategoryContent nvarchar(200)

set @Prev=(select max(id) from vNewsCategoryByNewsArticle where id<@NewsID and topid=@topid and status=1)
set @Next=(select min(id) from vNewsCategoryByNewsArticle where id>@NewsID and topid=@topid and status=1)
if @Prev is not null
begin
set @PrevTitle=(select title from vNewsCategoryByNewsArticle where id=@Prev and topid=@topid)
set @PrevCategoryContent=(select topid from vNewsCategoryByNewsArticle where id=@Prev and topid=@topid)
end
else
begin
set @Prev=0
set @PrevCategoryContent=‘‘
set @PrevTitle=‘‘
end
if @Next is not null
begin
set @NextTitle=(select Title from vNewsCategoryByNewsArticle where id=@Next and topid=@topid)
set @NextCategoryContent=(select topid from vNewsCategoryByNewsArticle where id=@Next and topid=@topid)
end
else
begin
set @Next=0
set @NextCategoryContent=‘‘
set @NextTitle=‘‘
end
begin
select @Prev as Prev,@Next as Next,@PrevTitle as PrevTitle,
@NextTitle as NextTitle,
@PrevCategoryContent as PrevCategoryContent,
@NextCategoryContent as NextCategoryContent
end

查看文章的上一篇下一篇的逻辑总结

原文:http://www.cnblogs.com/snowforever/p/3528048.html

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