Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS For Loop Container with Date Variable

I want to create a monthly package that executes a daily query at ODBC and writes an output file.

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').

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?

like image 574
Avlio Avatar asked Dec 08 '25 11:12

Avlio


1 Answers

Break it into parts as follows:

  1. Declare variables to store previous month start and end date as follows:

start_date(datetime) = (DT_DATE)((DT_WSTR,4)YEAR(DATEADD("MM",-1,GETDATE()))+"-"+RIGHT("0"+(DT_WSTR,2)MONTH(DATEADD("MM",-1,GETDATE())),2)+"-01")

end_date(datetime) = DATEADD("D", -(DAY(GETDATE())),GETDATE())

  1. Declare variable Counter(datetime)

  2. Create a For loop container as follows :

img

  1. 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
like image 129
Prabhat G Avatar answered Dec 10 '25 14:12

Prabhat G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!