有一个表,有个字段a,a表中的数据为
a     b
1     test1
2     test2
3     test3
4     test4目的:检索a为4,5,6的值
限制:在这个表中不一定有a字段为4,5,6的记录,所以用a in (4,5,6)是不行的,这个4,5,6为自然数,不是存在数据库中的
预想结果
   4      test4
   5
   6      
这个问题不是用存储过程,只是一句话sql解决,有高人么,我想不到更多的sql文法了~~

解决方案 »

  1.   

    select * from  dbo.a where a between 4 and 6
      

  2.   

    楼上的仍然不是正解,between and 和 in的结果是一样的~~
      

  3.   

    create table [你的表](a int,b varchar(100))
    insert into [你的表](a,b)values(1,'test1')
    insert into [你的表](a,b)values(2,'test2')
    insert into [你的表](a,b)values(3,'test3')
    insert into [你的表](a,b)values(4,'test4')select top 100 id=identity(int,4,1) into #tmp from syscolumns a 
    select a.id,case when b.b is null then ' ' else b.b end from  #tmp a left join [你的表] b on a.id=b.a where a.id between 4 and 6
    drop table #tmp
    drop table [你的表]