create table #t( id int ) insert #t select 1 union select 50 union select 23 union select 8select * from #t order by case id when 1 then 1 when 50 then 2 when 23 then 3 when 8 then 4 else 9 end
declare @s varchar(10) set @s='1,50,23,8' select * from 表 order by charindex(','+cast(id varchar)+',',','+@s+',')
select * from (select t.* ,1 as idn from t where id=1 union select t.* ,2 as idn from t where id=50 union select t.* ,3 as idn from t where id=23 union select t.* ,4 as idn from t where id=8) A order by A.idn
select* from 表a where id in(1,50,23,8) order by case id WHEN '1'THEN '1' WHEN '50' THEN '2' WHEN '23' THEN '3' WHEN '8' THEN '4' END
create table #t(
id int
)
insert #t select 1
union select 50
union select 23
union select 8select * from #t order by
case id
when 1 then 1
when 50 then 2
when 23 then 3
when 8 then 4
else 9 end
set @s='1,50,23,8'
select * from 表
order by charindex(','+cast(id varchar)+',',','+@s+',')
select * from
(select t.* ,1 as idn from t where id=1
union
select t.* ,2 as idn from t where id=50
union
select t.* ,3 as idn from t where id=23
union
select t.* ,4 as idn from t where id=8) A
order by A.idn
order by
case id WHEN '1'THEN '1' WHEN '50' THEN '2' WHEN '23' THEN '3' WHEN '8' THEN '4' END