要是有唯一标识就好办了
declare @id int
set @id = 10
select * from table where id = @id -1select * from table where id = @id +1
declare @id int
set @id = 10
select * from table where id = @id -1select * from table where id = @id +1
调试欢乐多
----
这个ID是每一次处理动态生成的select ....,id=identity(int,1,1) into #tmp from table
select * from #tmp where abs(id - @id) = 1
SELECT * FROM table1 WHERE id = (SELECT isnull(MAX(id),@id) FROM table1 WHERE id<@id )
下一条:
SELECT * FROM table1 WHERE id = (SELECT isnull(MIN(id),@id) FROM table1 WHERE id>@id )