Grab the filename of a flatfile, assign it to a variable to insert into an import history table, without for each loop.
Hi, I've got a static flat file connection which is used to populate a table. I want to know how to grab the name of this file to assign it to a variable, and then insert audit details into a history table after successfully populating the data table. I DO NOT want to use the FOR EACH loop because i only have one file to import. Could someone please help with as much details as possible. i'm a noob at this. Thanks in advance.
November 4th, 2012 11:26pm

you can use script task for the same ... here is the example.. --Let us TRY this | My Blog :: http://quest4gen.blogspot.com/
Free Windows Admin Tool Kit Click here and download it now
November 4th, 2012 11:51pm

Hi, Please find a link: SQLYoga Thanks, Tejas SQLYoga.comTejas Shah SQL YOGA
November 5th, 2012 12:11am

Thanks. But i'm still not clear how to grab the filename and assign it to a variable. Could you please post an example or something.
Free Windows Admin Tool Kit Click here and download it now
November 5th, 2012 12:41am

Thank you. I'm aware of this but it only adds the filename as a column for each records in the flat file. I need to assign the filename to a variable, to go into a separate import history table.
November 5th, 2012 12:42am

Hi, If you wanted to have a filename in a variable, I would prefer to have a SCRIPT task which reads the file name and assign it to variable, so you can use it. Thanks, Tejas SQLYogaTejas Shah SQL YOGA
Free Windows Admin Tool Kit Click here and download it now
November 5th, 2012 1:04am

Hi, I've got a static flat file connection which is used to populate a table. as you mention that you have a static flat file connection.. so get that file connection( as mention in previous post "Dts.Connections(ConnMgrA)") and then you can read the file name with "Path.GetFileName(fileName)" check this msdn linkLet us TRY this | My Blog :: http://quest4gen.blogspot.com/
November 5th, 2012 1:30am

Hi, Thanks. That was much helpful. Not as complete an answer as i hoped for because i'm a complete noob (both at SSIS and the forums :D ). Your answer however did send me to the right track. It turns out the script was a VB script. I'm more used to C#. (I failed to mention this, my bad). It all worked out in the end and it works for what i want it to do now. Thank you very much. Appreciate the help. The solution was as simple as this. Create a script task, public void Main() { Dts.Variables["fileName"].Value = Dts.Connections["Name_of_Connection"].ConnectionString.ToString(); Dts.TaskResult = (int)ScriptResults.Success; } I could then perform and insert into the table using the "fileName" variable along with usual datetime columns etc. Case closed! Thanks all for the help. :-)
Free Windows Admin Tool Kit Click here and download it now
November 6th, 2012 6:10pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics