我必须在 ssis 变量中动态获取当前周星期一的日期。有人可以帮我吗?能够进入 SQL 服务器,但在 SSIS 中不能这样做
问问题
54 次
1 回答
0
您可以使用 SQL 获取星期一的日期,然后使用执行 sql 任务设置变量。像这样的东西:
WITH ids
AS (SELECT TOP (14)
id = ROW_NUMBER() OVER (ORDER BY (SELECT 1)) - 7
FROM sys.columns)
, alldates
AS (SELECT dates = DATEADD(DAY, ids.id, CONVERT(DATE, GETDATE()))
, week_num = DATEPART(WEEK, DATEADD(DAY, ids.id, CONVERT(DATE, GETDATE())))
, day_of_week = DATENAME(WEEKDAY, DATEADD(DAY, ids.id, CONVERT(DATE, GETDATE())))
, current_week = DATEPART(WEEK, GETDATE())
FROM ids)
SELECT alldates.dates
FROM alldates
WHERE alldates.week_num = alldates.current_week
AND alldates.day_of_week = 'Monday';
于 2021-08-25T14:03:37.623 回答