有一个字段id 字符型数字 
输入两个数字 按数字大小把两个数字之间的数字全部查出来包括输入的两个数字

解决方案 »

  1.   

    declare @a int
    declare @b int
    select * from table where id between @a and @b
    这样?
      

  2.   

    忘排序了 从小到大ASC 从大到小DESCdeclare @a int 
    declare @b int 
    select * from table where id between @a and @b order by id ASC 
      

  3.   

    select * from table where id between 5 and 9 
      

  4.   

    如实是LS的,岂不是太简单了,LZ是这意思?
      

  5.   

    --这样?--问题太简单了?select *
    from 表名
    where id between 100 and 200
      

  6.   

    LZ是这意思吗?
    呵呵,LZ快回答吧,虽然我写了答案,但也不是很相信。
      

  7.   

    select * from tb where id >= @id1 and id <= @id2select * from tb where id between @id1 and @id2
      

  8.   

    declare @m int, @n int 
    select @m=2, @n=10
    select * from tb where id between @m and @n
      

  9.   

    又in比较好吧
    select * from tb where id in(@M,@n)
      

  10.   

    create table tb(id varchar(8))insert tb select '2'
    union all select '4'
    union all select '5'
    union all select '006'
    union all select '7'
    union all select '8'declare @m int, @n int 
    select @m=2, @n=7
    select * from tb where id between @m and @ndrop table tb/*
    id
    --------
    2
    4
    5
    006
    7(5 row(s) affected)
    */
      

  11.   

    declare @a varchar(4)
    declare @b varchar(4)select * from tb where id between cast(@a as int) and cast(@b as int) 
    order by cast(id as int)ASC这样呢?
      

  12.   

    字符型按数值比较,还是按字符比较?
    如果按字符比较:select * 
    from 表名 
    where id between '100' and '200'如果按数值比较,需要先转换一下:select * 
    from 表名 
    where id between cast('001' as int) and cast('00200' as int)
      

  13.   

    select * from tb where id  >= @id1 and id  <= @id2 select * from tb where id between @id1 and @id2