order by substring(字段名,2,len(字段名)) 

解决方案 »

  1.   


    order   by   convert(int,substring(字段名,2,len(字段名)))
      

  2.   


    create table #T(ID varchar(10))declare @s varchar(1000)
    select @s='insert into #t select '+replace(''''+'A1,A11,A12,A2,A3,A4,A5,A6,A7,A8,A9,A10'+'''',',',''' union all select ''')
    exec(@s)select * from #t order by len(id),id
    ID
    ----------
    A1
    A2
    A3
    A4
    A5
    A6
    A7
    A8
    A9
    A10
    A11
    A12(12 行受影响)
      

  3.   

    create table #
    (name varchar(10))
    insert into #
    select 'A1' UNION ALL
    select 'A2' UNION ALL
    select 'A3' UNION ALL
    select 'A4' UNION ALL
    select 'A5' UNION ALL
    select 'A6' UNION ALL
    select 'A7' UNION ALL
    select 'A8' UNION ALL
    select 'A9' UNION ALL
    select 'A10' UNION ALL
    select 'A11' UNION ALL
    select 'A12' 
    --原来排序
    SELECT * FROM # ORDER BY name /*
    name       
    ---------- 
    A1
    A10
    A11
    A12
    A2
    A3
    A4
    A5
    A6
    A7
    A8
    A9(所影响的行数为 12 行)*/
    SELECT * FROM # ORDER BY cast(substring(NAME,2,len(name)-1)as int)--现在排序/*
    name       
    ---------- 
    A1
    A2
    A3
    A4
    A5
    A6
    A7
    A8
    A9
    A10
    A11
    A12(所影响的行数为 12 行)*/
      

  4.   


    order by len(字段名),字段名这个方法不错啊!