排列顺序

来源:互联网 发布:淘宝会员抓取软件骗局 编辑:程序博客网 时间:2024/04/25 02:27

declare @t1 table (id int,field nvarchar(5))
insert into @t1 select 3,N'记录1'
     union all select 2,N'记录2'
     union all select 1,N'记录2'
     union all select 2,N'记录1'
    union all select 3,N'记录2'
     union all select 1,N'记录1'
select *
from @t1
where id in (1,2)
order by
    case id
         when  1 then 1
         when  2 then 2
    end

 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

declare @t1 table (id varchar(5),field nvarchar(5))
insert into @t1 select 3,N'记录1'
     union all select 2,N'记录2'
     union all select 1,N'记录2'
     union all select 2,N'记录1'
    union all select 3,N'记录2'
     union all select 1,N'记录1'
select *
from @t1
where id in (1,2)
order by charindex (','+id+',',',1,2,')