select top 1 * from table where id > 300 order by asc
union
select top 1 * from table where id < 300 order by desc

解决方案 »

  1.   

    select top 3 with ties * from t order by abs(id-300)
      

  2.   

    alter table A add ID1 int idendity primary key
    select * from A where ID1=(select ID1 from A where id=300)-1
                 or ID1=(select ID1 from A where id=300)+1
      

  3.   

    select * from table where id in 
    (select min(id) from table where id>300
     union 
    select max(id) from table where id<300)
      

  4.   

    select top 2 with ties * from t where abs(id-300)>0 order by abs(id-300)