May 11, 2010 at 12:22 pm
I am loading a text file. I need to extract that input text file's filename and location and then insert that information into the "filename" column of a SQL Server table. Is SSIS 2005 capable of this? If so, how?
May 11, 2010 at 12:29 pm
You can do that.. assuming that you have a variable which stores the complete path of the file like C:\foldername\foldername\filename.. if so, then create another variable and use substring and Findstring functions to extract the filename and then use it in the derived column of your data flow task.. If you can post your complete path, i can help you with the expression to extract the filename
May 11, 2010 at 12:48 pm
Good advice! Now how can I automatically derive the path and filename of the file?
May 11, 2010 at 1:15 pm
If you are loading a static text file, you already know its name - so you're not doing that, I'm guessing.
If you are loading multiple dynamically named text files, I'm guessing you're using a Foreach loop. This loop also allows you to map the 'filename being processed' to a variable. It's all done for you.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
May 11, 2010 at 1:28 pm
I believe it is one file, but the name is dynamic. Could the loop work if there is technically only one file?
May 11, 2010 at 1:59 pm
The Foreach loop will look at a folder, optionally subfolders, and files of a certain pattern if you are using wildcarding.
If only one file meets the criteria then yes the Foreach loop will work on one file.
May 12, 2010 at 5:54 am
Read this article:
If you are using the Flat File Source, you can directly store the filename in a column. If you only need the filepath and the filename in seperate columns, then you can use a derived column to split it out.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
May 14, 2010 at 4:56 pm
This will be excellent for me. Thank you very much.
May 15, 2010 at 9:45 pm
I have another question. This method stores the file name. What if I want to get other file information such as file size, file date, etc.?
May 16, 2010 at 11:58 pm
I don't think that SSIS has built-in features to get that sort of information, so I think you'll have to script in .NET to obtain that info.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
May 17, 2010 at 6:46 am
I have two questions:
1) Is the Multiple Flat File Connector exclusive to 2008 or is it also available in 2005?
2) How exactly do I get the Foreach Loop to send the filename to the Flat File Connection?
May 17, 2010 at 7:53 am
1) It is only for 2008 or higher (unless it will be tossed away, as this blog post is hoping for: http://sqlblog.com/blogs/jamie_thomson/archive/2010/05/11/five-things-ssis-should-drop.aspx)
2) Create a variable that will hold the filename found by the container. In the For Each Loop editor, go to the Variable Mapping tab and map the variable you created to index 0.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
May 17, 2010 at 11:52 am
Just out of curiosity, I noticed that my source filenames have different lengths. How do I derive just the file name (no extension and no path) when the filenames have different lengths?
May 17, 2010 at 12:06 pm
You need to split the file name into strings. You can use searches to find the slash and the period and get the substring between them.
Some hints:
http://www.sqlservercentral.com/Forums/Topic679052-148-1.aspx
May 17, 2010 at 12:58 pm
Back to the original Foreach Loop, I followed these steps:
1. Added the Foreach Loop Container and added the existing Data Flow Task to it.
2. Set the Container's Enumerator configuration to retrieve the Name and extension.
3. Clicked on Variable Mappings and set the User::varDealName to an index of 0.
4. Went to the Properties of the File Connection.
5. Clicked on Expressions. Set Property to ConnectionString and Expression to User::varDealName.
6. Received an error message: "There was no expression to compute. An attempt was made to compute or get the string of an empty expression."
What am I doing wrong?
Viewing 15 posts - 1 through 15 (of 17 total)
You must be logged in to reply to this topic. Login to reply