比如 值1:10001   值2:10005结果
10002
10003
10004

解决方案 »

  1.   

    select *
    from tb
    where 列1 > 值1 and 列1 < 值2
      

  2.   

    select * from tb where col>值1 and col<值2
      

  3.   

    declare @n1 int ,@n2 int 
    declare @s table (a int)
    set @n1=10001 
    set @n2=10005
    while(@n1<@n2-1)
    begin 
    insert @s values(@n1+1)
    set @n1=@n1+1
    end
    select * from @s
    /*
    a
    -----------
    10002
    10003
    10004
    */
      

  4.   

    @s:10001  @e:10005 select @s + number
    from master..spt_values 
    where type = 'P'
          and @s + number between @s and @e
      

  5.   

    修改下石头哥的,。,
    declare @n1 int ,@n2 int 
    set @n1=10001 
    set @n2=10005
    select @n1 + number  as K
    from master..spt_values 
    where type = 'P' 
          and @n1 + number > @n1 and  @n1 + number <@n2/*
    K
    -----------
    10002
    10003
    10004
    */
      

  6.   


    这个没注意 到,汗
    where type = 'P' 
          and @n1 + number between  @n1+1 and  @n2-1
      

  7.   

    不用系统表,还有别的方法吗?
    sqlserver2005有没有函数 select 某函数(v1,v2)实现同样的功能?
      

  8.   


    create function dbo.f_jj(
     @n1 int ,@n2 int) 
     returns  @s table (a int)
     as
    begin 
    while(@n1<@n2-1)
    begin 
    insert @s values(@n1+1)
    set @n1=@n1+1
    end
    return 
    end
    select * from dbo.f_jj(10001,10005)
    /*
    a
    -----------
    10002
    10003
    10004
    */
      

  9.   

    可以 create  function dbo.f_jj(
     @n1 varchar(10) ,@n2 varchar(10)) 
     returns  @s table (a varchar(10))
     as
    begin 
    while(@n1<@n2-1)
    begin 
    insert @s values(@n1+1)
    set @n1=@n1+1
    end
    return 
    end
    select * from dbo.f_jj('10001','10005')
    /*
    a
    -----------
    10002
    10003
    10004
    */
      

  10.   


    select * from dbo.f_jj('abc','abe')?
      

  11.   

    哈哈,我说的字符不能转为int
      

  12.   


    declare @t1 table(id varchar(20))
    insert @t1
    select 'abc' union all
    select 'abd' union all
    select 'abe'select * from @t1 
    where id > 'abc' and id < 'abe'
    --结果
    id
    abd
      

  13.   

    求介于‘abc'和'abf'之间的数据(只知道这两个值,没有表)
    结果应该是:
    abd
    abe麦蒂的方法是针对可转化为整数的字符的 
    如‘10005’
      

  14.   

    你这个要是有规律的话,可以用ASCII 和CHAR函数来解决,要不然还是复杂
      

  15.   

    with cte as (
    select '10001' a union all select '10002' union all select '10003'union all select '10004')select * from cte
    where a between '10001' and '10004'a
    --------
    10001
    10002
    10003
    10004with cte as (
    select 10001 a union all select 10002 union all select 10003 union all select 10004)select * from cte
    where a between 10001 and 10004a
    --------
    10001
    10002
    10003
    10004
      

  16.   

    用ASCII应该可以实现字符的连续,但是估计实现多位的就不大好写了,还是应该看具体需求,浅见
      

  17.   


    declare @s varchar(10)
    declare @e varchar(10)
    set @s = 'abc'
    set @e = 'abf'
    select left(@s,len(@s) -1) + char(ascii(right(@s,1))+ number)
    from master..spt_values
    where type = 'P'
          and ascii(right(@s,1)) + number between ascii(right(@s,1))+1 and ascii(right(@e,1))-1
          
    /*
    -----------
    abd
    abe(2 行受影响)
    */