SQL一直是初级级别,慢慢进步,写了个日期转星期的函数,大家多多点评,也给自己留作笔记。
CREATE Function GetDay(@rq datetime)
returns varchar(10) as
begin
declare @str varchar(10)
set @str=case
when datepart(dw,@rq)=1 then 'Sun'
when datepart(dw,@rq)=2 then 'Mon'
when datepart(dw,@rq)=3 then 'Tue'
when datepart(dw,@rq)=4 then 'Wed'
when datepart(dw,@rq)=5 then 'Thu'
when datepart(dw,@rq)=6 then 'Fri'
when datepart(dw,@rq)=7 then 'Sat'
else null end
return @str
end
returns varchar(10) as
begin
declare @str varchar(10)
set @str=case
when datepart(dw,@rq)=1 then 'Sun'
when datepart(dw,@rq)=2 then 'Mon'
when datepart(dw,@rq)=3 then 'Tue'
when datepart(dw,@rq)=4 then 'Wed'
when datepart(dw,@rq)=5 then 'Thu'
when datepart(dw,@rq)=6 then 'Fri'
when datepart(dw,@rq)=7 then 'Sat'
else null end
return @str
end