我想对一字符序号字段排序,比如该序号字段值为1,2,3....10,11,12...20,21...
    如果用ORDER BY 该字段  来排序,那么11会出现在1和2之间.我该怎么使用ORDER BY 子句  

解决方案 »

  1.   

    order by len(xx),xxorder by cast(xx as int)order by cast(xx as float)
      

  2.   

    select * from table
    order by cast(字段 as int)
      

  3.   

    order   by   cast(xx   as   int) 
      

  4.   

     我想对一字符序号字段排序,比如该序号字段值为1,2,3....10,11,12...20,21... 
            如果用ORDER   BY   该字段     来排序,那么11会出现在1和2之间.我该怎么使用ORDER   BY   子句     order by cast(字段 as int/bigint)
      

  5.   

    declare @tb table(id varchar(10),name varchar(10))
    insert into @tb select '1','a'
    insert into @tb select '2','a'
    insert into @tb select '3','a'
    insert into @tb select '4','a'
    insert into @tb select '5','a'
    insert into @tb select '6','a'
    insert into @tb select '7','a'
    insert into @tb select '8','a'
    insert into @tb select '9','a'
    insert into @tb select '10','a'
    insert into @tb select '11','a'
    insert into @tb select '12','a'
    select * from @tb order by cast(id as int)
    select * from @tb order by replicate('0',5-len(id))+idid name
    1 a
    2 a
    3 a
    4 a
    5 a
    6 a
    7 a
    8 a
    9 a
    10 a
    11 a
    12 a