首页 > 其他 > 详细

根据日期得到星期的函数

时间:2017-01-03 15:13:25      阅读:189      评论:0      收藏:0      [点我收藏+]

--最直接的方式就是用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 星期

 

--今天的星期

/*

星期

--------

星期六

*/

根据日期得到星期的函数

原文:http://www.cnblogs.com/accumulater/p/6244607.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!