I’m doing an Excel loop through fifty or more Excel files. The loop goes through each Excel file, grabs all the data and inputs it into the database without error. This is the typical process of setting delay validation to true, and making sure that the expression for the Excel Connection is a string variable called EFile that is set to nothing (in the loop).
What is not working: trying to input the name of the Excel file into the database.
What’s been tried (edit; SO changed my 2 to 1 – don’t know why):
-
Add a derived column between the Excel file and database input, and add a column using the EFile expression (so under Expression in the Derived Column it would be @[User::EFile]). and add the empty. However, this inputs nothing a blank (nothing).
-
One suggestion was to add ANOTHER string variable and set its properties EvaluateAsExpression to True and set the Expression to the EFile variable (@[User::EFile]). The funny thing is that this does the same thing – inputs a blank into the database.
Numerous people on blogs claim they can do this, yet I haven’t seen one actually address this (I have a blog and I will definitely be showing people how to do this when I get an answer because, so far, these others have fallen short). How do I grab an Excel file’s name and input it in a database during a loop?
Added: Forgot to add, no scripts; the claim is that it can be done without them, so I want to see the solution without them.
Note: I already have the ability to import the data from the Excel files – that’s easy (see my GitHub account, as I have two different projects for importing all sorts of txt, csv, xls, xlsx data). I am trying to also get the actual name of the file being imported also into the database. So, if there are fifty Excel files, along with the data in each file, the database will have the fifty file names alongside that data (so if each file has 1000 rows of data, each 1000 rows would also have the name of the file they came from next to them as an additional column). This point seems to cause a lot of confusion, as people assume I’m having trouble importing data in files – NOPE, see my GitHub; again that’s easy. It’s the FILENAME that needs to also be imported.
Test package: https://github.com/tmmtsmith/SSISLoopWithFileName
Solution: @jaimet pointed out that the Derived Column needed to be the @[User::CurrentFile] (see the test package). When I first ran the package, I still got a blank value in my database. But when we originally set up the connection, we do point it to an actual file (I call this “fooling the package”), then change the expression on the connecting later to the @[User::CurrentFile], which is blank. The Derived Column, using the variable @[User::CurrentFile], showed a string of 0. So, I removed the Derived Column, put the full file path and name in the variable, then added the variable to the Derived Column (which made it think the string was 91 characters long), then went back and set the variable to nothing (English teacher would hate the THENs about right now). When I ran the package, it inputted the full file path. Maybe, like the connection, it needs to initially think that a file exists in order for it to input the full amount of characters?
Appreciate all the help.
Tim,
You’re using the wrong variable in your Derived Column component. You are storing the filename in @[User::CurrentFile] but the variable that you’re using in your Derived Column component is @[User::FileNameInput]
Change your Derived Column component to use @[User::CurrentFile] and you’ll be good.
Hope that helps.
JT