2,498
社区成员
发帖
与我相关
我的任务
分享
/*
2008-04-13 00:00:00.000 星期日
2008-04-14 00:00:00.000 星期一
2008-04-08 00:00:00.000 星期二
2008-04-09 00:00:00.000 星期三
2008-04-10 00:00:00.000 星期四
2008-04-11 00:00:00.000 星期五
2008-04-12 00:00:00.000 星期六
*/
select t_day,
case datepart(dw,t_day) when 2 then '星期一'
when 3 then '星期二'
when 4 then '星期三'
when 5 then '星期四'
when 6 then '星期五'
when 7 then '星期六'
when 1 then '星期日'
end from tb order by
case datepart(dw,t_day) when 2 then 1
when 3 then 2
when 4 then 3
when 5 then 4
when 6 then 5
when 7 then 6
when 1 then 7
end
/*
结果:
2008-04-14 00:00:00.000 星期一
2008-04-08 00:00:00.000 星期二
2008-04-09 00:00:00.000 星期三
2008-04-10 00:00:00.000 星期四
2008-04-11 00:00:00.000 星期五
2008-04-12 00:00:00.000 星期六
2008-04-13 00:00:00.000 星期日
*/
with adoquery1 do begin
close;
sql.text:='select * from tb order by '+
'case datepart(dw,t_day) when 2 then 1 '+
'when 3 then 2 '+
'when 4 then 3 '+
'when 5 then 4 '+
'when 6 then 5 '+
'when 7 then 6 '+
'when 1 then 7 end ';
open;
end;
declare @t table (a varchar(10))
insert into @t select 'a'
insert into @t select 'b'
insert into @t select 'c'
select case a when 'a' then 1 when 'b' then 3 when 'c' then 2 end id,* from @t order by id
/*
1 a
2 c
3 b
*/
declare @t table (a varchar(10))
insert into @t select 'a'
insert into @t select 'b'
insert into @t select 'c'
select * from @t
/*
a
b
c
*/
--想a ,c,b
declare @t table (a varchar(10))
insert into @t select 'a'
insert into @t select 'b'
insert into @t select 'c'
select * from @t order by case when a='a' then 1 when a='b' then 3 when a='c' then 2 end
/*
a
c
b
*/