I have a SQL statement that returns 600 PDF filenames that I need to use to move a copy of the file out of folder into a new folder (The filenames in the SQL are the exact name of the PDF files in the folder).
I have a execute SQL statement set up that passes the PDF name result set to a variable.
How can I use this variable to pass to file system task to only copy out the PDF filenames returned in SQL statement and passed to variable?
Thanks,
Also I am getting an eror
We can use Foreach Loop Container to find the files, then use empty Sequence Container, Precedence Constraint, File System Task to move the files to archive folder.
You to set following in Foreach Loop Containter : In Collection menu pick Foreach File Enumerator , choose you folder and file filter if you need to. In Variable Mappings menu choose a string variable and assing 0 index. Then place File System Task in foreach, and use the variable to move files.
ssis Move file from one folder to another From the Control Flow tab in your SSIS package, look in the SSIS Toolbox in the common section for the File System Task, drag this onto your design surface where you want the file move to happen in your package. Once you've placed the task, double click to open it.
This is a pretty simple design pattern in SSIS. Generally speaking, you'll get your list of file names from an Execute SQL Task
, set up a Foreach Loop Container
to process each file, and a File System Task
inside the loop.
To start, you'll want to make sure you have the following variables:
I'm using E:\Import\
as my source folder. That's where I expect all my files to be. You can change this to be the folder where your files are. I want to move files into a subfolder, so I've set the DestinationFolder
to E:\Import\Internal\
. Again, change this to suit your needs.
Additionally, you can see we have a Filenames
variable of type System.Object
. This is the ADO object that will hold the results of our SQL query. The Filename
string variable will be used to store each file name as we go through the loop.
SourcePath
and DestinationPath
we're going to configure to be populated by an expression. We're going to concatenate the folder names with our file names. To do that, open the variables window, and click on SourcePath
. Then edit the Properties
and set EvaluateAsExpression
to True
, and then set the expression to be @[User::SourceFolder] + @[User::Filename]
. Do the same for DestinationPath
, using the @[User::DestinationFolder]
variable in the expression. You should end up with your two *Path
variables looking something like this:
Now we can configure the Execute SQL Task
. Make sure you set the ResultSet
value to Full result set
and map the results with Result Name
equal to 0
to your ADO object variable Filenames
.
Next, create a Foreach Loop Container
and configure it to use the Foreach ADO Enumerator
type and point it to your Filenames
variable.
Go to Variable Mappings
and make sure to map User::Filename
to Index 0
.
Finally, create a File System Task
and put it inside the loop container. Then configure it to use your *Path
variables with the appropriate action.
When you're all done, you should having a package that looks like this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With