某table有一varchar字段_code,数据格式如下#1,#2,#3,……,#10,……,请问怎样写sql的order by 使select的结果如“#1,#2,#3,……,#10,……”排列?

解决方案 »

  1.   

    ORDER BY SUBSTRING(_code,2)+0
      

  2.   

    order by replace(_code,'#',1)
      

  3.   

    order by  cast(substring(name,2) as unsigned) asc
      

  4.   

    declare @myTable table(a varchar(10))
    insert into @myTable
    select '#1' union all
    select '#2' union all
    select '#3' union all
    select '#4' union all
    select '#5' union all
    select '#6' union all
    select '#7' union all
    select '#9' union all
    select '#10' union all
    select '#11' select * from @myTable order by convert(int,substring(a,2,len(a)))