要是有唯一标识就好办了
declare @id int
set @id = 10
select * from table where id = @id -1select * from table where id = @id +1

解决方案 »

  1.   

    select * from table where abs(id - @id) = 1
      

  2.   

    select * from table1 where id = (select max(id) from table1 where id<@id )
      

  3.   

    楼上的,你那种取法有问题,因为当某条记录删除后,ID就不连续了,不连续的记录中取不到它的上条或下条!
    ----
    这个ID是每一次处理动态生成的select ....,id=identity(int,1,1) into #tmp from table
    select * from #tmp where abs(id - @id) = 1
      

  4.   

    上一条:
    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 )