sql 返回 第几周
--孕妇预产期 周数 /****** 对象: 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
----返回星期名字 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
好不容易活着