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

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

 

转载于:https://www.cnblogs.com/snowforever/p/3528048.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值