直接 order by 字段 desc

解决方案 »

  1.   

    order by cast(字段 as datetime) desc
    ---手动加order by cast(字段+'-1' as datetime) desc
      

  2.   

    declare @ta table(name varchar(20))
    insert @ta
    select '2006-4'union all
    select '2006-7'union all
    select '2006-6'union all
    select '2006-5'union all
    select '2006-11'
    select * from @ta 
    order by case  when len(name)!>7 then  cast(name+'-01' as datetime)
    else cast(name as datetime) end
    desc(所影响的行数为 5 行)name                 
    -------------------- 
    2006-11
    2006-7
    2006-6
    2006-5
    2006-4(所影响的行数为 5 行)
      

  3.   

    select * from @a order by month(cast(aaa+'-1' as datetime)) desc