Reputation: 283
I have an SSIS package set up that imports downloaded data files to the database (one file at a time by date)
Current Setup (for a file):
Downloaded file is at location (same file exists between the date range 1st Feb to Today)
C:\DataFiles\GeneralSale_20170201.txt
In SSIS the variables - For each file there are 4 variables. First is the location of the where the file is, called @Location
The second simple gives the name of the file named @GeneralSales
returning the value
GeneralSale_
The third is the date (@ExportDateFormatted
) for which the code is, (DT_WSTR,8)(DATEPART("yyyy", @[User::ExportDate]) * 10000 + DATEPART("mm", @[User::ExportDate]) * 100 + DATEPART("dd", @[User::ExportDate]))
and [ExportDate]
is set as DATEADD("DD", 0, GETDATE())
.
[ExportDate]
allows me to set the file date (which is already downloaded) that I want to import in my table dbo.GeneralSale
i.e. If I want to import the file on 20170205 then I would adjust the export date and then run the package
The final variable is the @ExportFileExtension
returning the value
txt
Then in the DataFlow which looks like the below:
The flat file source connects to the connection string below. The Property > Expressions > ConnectionString
of the connection string runs the variables to make a file name. This is where I use the variables from before
@[User::Location] + @[User::GeneralSales] + @[User::ExportDateFormatted] + "." + @[User::ExportFileExtension]
Returning the value:
C:\DataFiles\GeneralSale_20170201.txt
This then populates the table with the data of that file. But to insert the date for another day I have to amend the date and run the package.
What I am trying to do is pass a start and end date to let the package insert all data from the files between those dates.
Hope the above information is clear of what goes on and what I am trying to achieve.
Upvotes: 0
Views: 147
Reputation: 5246
You need to iterate between two dates. In SSIS its pretty straightforward; I would describe the main steps:
StartDate
and EndDate
of type Date, and on the package start - validate that StartDate <= EndDate
. ExtrDate
, and add For Loop with settings initial Expression @ExtrDate = @StartDate
, Evaluation - @ExtrDate <= @EndDate
and Assign - @ExtrDate = DateAdd("dd", 1, @ExtrDate)
. Purpose of this loop is quite clear. ExtrDate
variable will be increased on each step of the loop.
Package parameters allow building more flexible package.
Upvotes: 1