表中有如下記錄
100B
100-B
100A
100-AORDER BY時.想按如下方式排列
100-A
100-B
100A
100B如何寫,不要急關回簽,有興趣的可以試一下."-"和"-"的排序很很怪.

解决方案 »

  1.   

    select * from tablename 
    where charindex('-',orderFieldName)>0
    order by orderFieldName
    union all
    select * from tablename 
    where charindex('-',orderFieldName)<0
    order by orderFieldName
      

  2.   

    这样可以吗:
    select *
    from (select '100B' as aaa
    union select '100-B'
    union select '100A'
    union select '100-A') a
    order by replace(aaa, '-', char(ascii('A') - 1))
      

  3.   

    这样可以吗:
    select *
    from (select '100B' as aaa
    union select '100-B'
    union select '100A'
    union select '100-A') a
    order by replace(aaa, '-', char(ascii('A') - 1))
    /*
    aaa
    100-A
    100-B
    100A
    100B
    */