try:select top 5 * from table1 order by abs(convert(int,replace(col1aaa,'记录',''))-4)

解决方案 »

  1.   

    应该可以实现,
    1、借助与临时表,给数据加上行号,
    2、select 行号 from table where 检索出符合记录的数据行号
    3、select * from table where 行号 in (将2检索出来的数据集作为条件)
    4.Ok
      

  2.   

    --参考:
    --找一条记录前后两条记录值(差值法)select top 2 a.id 
    from
    (select 0 as id from news  union select id from news) a 
    order by abs(a.id-给定id)
      

  3.   

    改一句
    3为where 行号 in () or 行号-1 in () or 行号-2 in () or 行号 +1 in() or 行号+2 in ()
      

  4.   

    假设你的表为:table1(record_col varchar(50))select identity(1,1) as id ,record_col into #t from table1select record_col from #t where (id-
    select id from #t where record_col='记录4')<3
      

  5.   

    我的表是这样的  
    用户编号 用户名称      用户地址  
    100416  卫强             环南一里11号  
    100516  陈济楫            环南一里91号  
    100519  朱锡威            环南一里89号  
    100659  叶愿             南门六巷74号  
    100758  黄永             南门六巷60号  
    100869  李伟良            环南一里87号  
    100998  何乃杰            南门六巷55号  
    101005  刘卓方            环南一里4号  
    101050  陈炽耀            环南一里6号  我想通过 select * from 表 where 用户名称='黄永' 选出这个用户,也顺便把 朱锡威、叶愿 李伟良 何乃杰 这4个用户select 出来
      

  6.   

    select *,identity(int,1,1) as id into #t from tb
    declare @id int
    select @id=id from #t where 用户名称='黄永'
    select * from #t where id between @id-2 and @id+2
    drop table #t
      

  7.   

    select id=identity(int,1,1),* into newtable from table
    select * from newtable where id between (select id from newtable where 用户名称='黄永')-2 and (select id from newtable where 用户名称='黄永')+2