create procedure test
@id int
as declare @previd int ,@nextid int
select @previd=max(id) from testft where id<@id
select @nextid=min(id) from testft where id>@idset @previd=isnull(@previd,0)
set @nextid=isnull(@nextid,0)select id,title,content,previd=@previd,nextid=@nextid from tb_news where id=@id
@id int
as declare @previd int ,@nextid int
select @previd=max(id) from testft where id<@id
select @nextid=min(id) from testft where id>@idset @previd=isnull(@previd,0)
set @nextid=isnull(@nextid,0)select id,title,content,previd=@previd,nextid=@nextid from tb_news where id=@id
@id int, --要查询的id
@preid int out, --前一条的id
@nextid int out, --后一条的id
as
select @preid=isnull(max(id),0) from tb_news where id<@id
select @nextid=isnull(min(id),0) from tb_news where id>@id
select * from tb_news where id=@id
go
--调用示例
declare @preid int,@nextid int
exec p_qry 1,@preid out,@nextid out
@id int --要查询的id
as
declare
@preid int , --前一条的id
@nextid int --后一条的id
select @preid=isnull(max(id),0) from aa where id<@id
select @nextid=isnull(min(id),0) from aa where id>@id
select *,@preid as Pre,@nextid as Next from aa where id=@id
GO
from tb_news where id=@id