CREATE OR REPLACE PROCEDURE "internal"."get_last_weekday_of_month"(AsofDate TIMESTAMP_NTZ(9))
RETURNS VARCHAR(16777216)
LANGUAGE SQL
AS
$$
DECLARE
LastWeekDay TIMESTAMP_NTZ(9);
BEGIN
truncate table "internal"."monthend_process";
LastWeekDay := DATEADD(DAY,CASE DAYOFWEEK(AsofDate)
WHEN 6 THEN -1
WHEN 7 THEN -2
ELSE 0
END, AsofDate);
INSERT INTO "internal"."monthend_process" ("MonthEndDates","created_on", "RollOverStartDate", "PrevPrevMonthEnd")
SELECT :LastWeekDay as "MonthEndDates", CURRENT_TIMESTAMP(), NULL,NULL
UNION
SELECT LAST_DAY(:AsofDate) as "MonthEndDates", CURRENT_TIMESTAMP(), NULL,NULL ;
UPDATE "internal"."monthend_process"
SET "RollOverStartDate" = DATEADD(DAY, -4, :AsofDate),
"PrevPrevMonthEnd" = LAST_DAY(DATEADD(MONTH, -1, :AsofDate));
RETURN 'Stored procedure executed';
END;
$$;
字符串
这个存储过程工作正常,但是当我传递任何星期天的日期时,它不会返回星期五的日期,而对于星期六,它工作正常,它返回星期五的日期。
1条答案
按热度按时间neekobn81#
我相信如果你改变以下内容:
字符串
下面它应该像你预期的那样工作:
型