测试:
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 行)
*/
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 行)
*/
-----------------------------
order by charindex(','+cast(b as char(1))+',',',3,2,1,4,')
这样总可以了吧。
order by charindex(','+cast(b as varchar())+',',',3,2,1,4,')