测试:
create table test(a  int identity(1,1), b int)insert into test (b)select 1
insert into test (b)select 3
insert into test (b)select 2
insert into test (b)select 4
insert into test (b)select 1select * from test
order by charindex(cast(b as char(1)),'3214')/*结果
a           b           
----------- ----------- 
2           3
3           2
1           1
5           1
4           4(所影响的行数为 5 行)
*/

解决方案 »

  1.   

    order by case when col=4 then 1 else 0 end,col desc
      

  2.   

    order by charindex(cast(b as char(1)),'3214')  这样如果有 21 怎么办
      

  3.   

    order by charindex(cast(b as char(1)),'3214')  这样如果有 21 怎么办
    -----------------------------
    order by charindex(','+cast(b as char(1))+',',',3,2,1,4,')  
    这样总可以了吧。
      

  4.   


    order by charindex(','+cast(b as varchar())+',',',3,2,1,4,')