sql 返回 第几周

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
--孕妇预产期 周数
/****** 对象:  UserDefinedFunction [dbo].[f_crm_getedcweek]    脚本日期: 07/27/2020 17:24:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[f_crm_getedcweek](@edc datetime)
RETURNS int
AS
BEGIN
     
    declare @edcweek int,@today datetime,@ledc datetime
    set @edcweek = 0
    set @today = convert(char(10),getdate(),126)
    if @edc >= @today
    begin
        set @ledc = @edc - 280;
        set @edcweek =   abs(datediff(day,@today,@ledc)  / 7);
        
    end
 
 
 
 
RETURN @edcweek
END<br><br><br><br>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
----返回星期名字
ALTER FUNCTION [dbo].[f_pre_getweekname](@date datetime,@weekname varchar(10) = '',@flag int = 0)
RETURNS varchar(10)
AS
BEGIN
declare @weekid int
declare @myweekname varchar(10)
if @flag = 0
begin
set @weekid = DATEPART(w,@date);
if @weekid = 7 set @myweekname = '星期六'
else if @weekid = 1 set @myweekname = '星期天'
else if @weekid = 2 set @myweekname = '星期一'
else if @weekid = 3 set @myweekname = '星期二'
else if @weekid = 4 set @myweekname = '星期三'
else if @weekid = 5 set @myweekname = '星期四'
else if @weekid = 6 set @myweekname = '星期五'
end
else if @flag = 1
begin
if @weekname = '星期六' set @weekid = 7
else if @weekname = '星期天' set @weekid = 1
else if @weekname = '星期一' set @weekid = 2
else if @weekname = '星期二' set @weekid = 3
else if @weekname = '星期三' set @weekid = 4
else if @weekname = '星期四' set @weekid = 5
else if @weekname = '星期五' set @weekid = 6
end
 
if @flag = 1 set @myweekname = cast(@weekid as varchar(10))
return @myweekname
 
END

  

posted @   黑贝是条狗  阅读(531)  评论(0编辑  收藏  举报
编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· DeepSeek火爆全网,官网宕机?本地部署一个随便玩「LLM探索」
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 上周热点回顾(1.20-1.26)
· 【译】.NET 升级助手现在支持升级到集中式包管理
点击右上角即可分享
微信分享提示