SSIS带日期变量的循环容器 [英] SSIS For Loop Container with Date Variable
问题描述
我想创建一个每月包,在ODBC上执行每日查询并写入输出文件。
I want to create a monthly package that executes a daily query at ODBC and writes an output file.
更具体地说,查询必须在上个月(例如'01 / 11/2018')
,然后是下一个('02/11/2018')
,直到上个月的最后一天('30/11 / 2018')
。
More specifically the query must be first executed for the first day of the previous month (e.g. '01/11/2018')
then the next one ('02/11/2018')
until the last day of the previous month ('30/11/2018')
.
日期变量当前被保存为字符串,我还希望将具有Oracle日期格式的字符串变量插入查询中。应该如何组织?有没有一种方法可以在表达式中使用字符串变量?
The date variables are currently saved as Strings and I also want to have a string variable with Oracle date format to be inserted into the query. How should it be organised? Is there a way that I could use the string variables in the expressions?
推荐答案
将其分成以下部分:
- 声明变量以存储上个月的开始和结束日期,如下所示:
开始日期(日期时间) = (DT_DATE)((DT_WSTR,4)YEAR(DATEADD( MM,-1,GETDATE()))+ - + RIGHT( 0 +(DT_WSTR,2)MONTH(DATEADD( MM,-1,GETDATE())),2)+-01)
结束日期(日期时间) = DATEADD( D,-(DAY(GETDATE())),GETDATE())
-
声明变量
Counter(datetime)
创建一个 For循环容器
如下:
- For循环容器中应该有其余的数据流任务,这将创建输出文件。您可以在SQL中使用变量
Counter
对其进行参数化
- Rest of the Data Flow Task should be there within For loop container, which will create output file. You can use the variable
Counter
in SQL to parameterize it
这篇关于SSIS带日期变量的循环容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!