cool hit counter [T-SQL] Get the common nodes before and after the specified date (beginning of month, end of Monday, weekend, etc.)_Intefrankly

[T-SQL] Get the common nodes before and after the specified date (beginning of month, end of Monday, weekend, etc.)


Note: The week nodes are based on Chinese custom, which regards Monday as the beginning and Sunday as the end.

/*---------------------------------
 function: Get a specific start and end date for a datev0.02
Author:AhDung
Update:201607251729。 whether@@datefirst why is it worth, None of which affects the weekly node
---------------------------------*/
ALTER FUNCTION dbo.FGetSpecialDate_ahdung(@date DATE, @SpcDate VARCHAR(20))
RETURNS DATE AS
BEGIN
IF @date IS    NULL RETURN NULL
IF @SpcDate IN ('YearBeg','YB','NC',' early') RETURN DATENAME(YEAR,@date)+'-01-01'
ELSE IF @SpcDate IN ('YearEnd','YE','NW',' end of the year',' end of the year') RETURN DATENAME(YEAR,@date)+'-12-31'
ELSE IF @SpcDate IN ('QuarterBeg','QtBeg','QB','JC',' early season') RETURN DATENAME(YEAR,@date)+CASE WHEN MONTH(@date)<=3 THEN '-01' WHEN MONTH(@date)<=6 THEN '-04' WHEN MONTH(@date)<=9 THEN '-07' ELSE '-10' END +'-01'
ELSE IF @SpcDate IN ('QuarterEnd','QtEnd','QE','JW',' end of the season',' end of season') RETURN DATENAME(YEAR,@date)+CASE WHEN MONTH(@date)<=3 THEN '-03-31' WHEN MONTH(@date)<=6 THEN '-06-30' WHEN MONTH(@date)<=9 THEN '-09-30' ELSE '-12-31' END
ELSE IF @SpcDate IN ('MonBeg','MB','YC',' early in the month') RETURN CONVERT(CHAR(7),@date,120)+'-01'
ELSE IF @SpcDate IN ('MonEnd','ME','YW',' end of the month',' late in the month') RETURN DATEADD(DAY,-1,CONVERT(CHAR(7),DATEADD(MONTH,1,@date),120)+'-01')
ELSE IF @SpcDate IN ('WeekBeg','WB','ZY',' Monday','WeekEnd','WE','ZR','ZM',' diurnal',' weekends')
BEGIN
DECLARE @dw INT=DATEPART(dw,@date)
DECLARE @diff INT = 9-@@DATEFIRST
DECLARE @d INT= CASE WHEN @dw<@diff THEN @dw+7 ELSE @dw END
IF @SpcDate IN ('WeekBeg','WB','ZY',' Monday') RETURN DATEADD(DAY,@diff-@d,@date)
RETURN DATEADD(DAY,@diff-@d+6,@date)
END
RETURN @date
END

Recommended>>
1、Spark Performance Tuning from the Ground Up
2、Idiots believers pioneers a history of the neural network renaissance in the mouth of the deep learning triumvirate and others
3、Arcgis annotation tips
4、Tsinghua Bingo AIthemed study dismantling robots DIY remote control buggies and having fun to the max
5、Good news Beidou Academy was recognized as a Provincial New RD Institution and a National Hightech Enterprise

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号