`
yiyeqinghuasoon
  • 浏览: 644430 次
文章分类
社区版块
存档分类
最新评论

【叶子函数分享二十七】根据日期得到星期的函数

 
阅读更多

--最直接的方式就是用case when判断,这里用表变量来处理的

go

--创建函数

create function [dbo].[m_getweek](@date nvarchar(2000))

returns varchar(2000)

AS

begin

declare @weekday nvarchar(300)

declare @table table (id int ,weekday nvarchar(200))

insert into @table

select 0,'星期天' union select 1,'星期一' union select 2,'星期二' union

select 3,'星期三' union select 4,'星期四' union select 5,'星期五' union select 6,'星期六'

select @weekday=weekday from @table where id=(datepart(dw,@date)-1)

return @weekday

end

--测试示例

select [dbo].[m_getweek](getdate()) as 星期

--今天的星期

/*

星期

--------

星期六

*/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics