I have an SSIS package that loops through a list of Excel files and imports all the data; easy stuff. Works perfectly.
The addition to this is that I need to store the filename of the Excel file with the data; so that I can run queries against this additional column and input it into the main table. These files may have hundreds of rows of data, and when inputted into the main table, I need the name of the file in an additional column entered with them.
Example: 25 Excel file names with names like EUROMMYYYY, USDMMYYYY, CNYMMYYY, etc; the columns in the Excel files are Day, Percent Move, Exchange, etc - I would have an additional column in my database that had "FileName" so that all the Excel data would be entered and the filename would be entered as well. The database result would look like
Day Percent Exchange FileName (this comes from the file name and isn't in the file)
1 12% DXC EUROMMYYYY
2 9% DXC EUROMMYYYY
3 4% DXC EUROMMYYYY
My immediate thought was to run a C# script to grab the filename of Excel, add an additional row to the Excel file, and then import that additional row as well. However, the code just to do that turned into a nightmare of complexity, as Excel and C#
don't play nice with each other.
Anyone done something similar this: Google searches only yield people who need this code for a loop (which means they're doing it wrong, as you don't have to grab the file name for that - just set up the appropriate variable). This case differs because
I need the file name to be inserted into the database along with the other data.