0

What is the best was I can open a txt file in a SSIS and store the first line as a variable.

I want to put a list of accounts in the txt file and use them in a SQL task.

ojhawkins
  • 3,200
  • 15
  • 50
  • 67
  • 1
    I believe that [this is the way to go](http://stackoverflow.com/questions/10324149/ssis-how-do-i-load-data-from-text-files-where-the-path-of-files-is-inside-anot). Only difference is you don't have tzo iterate all of the rows, so it should be simpler. – OzrenTkalcecKrznaric Jul 18 '13 at 06:43

1 Answers1

2

Refer to the link @Ozren gave you, to create a proper flat file connection e.g myfile and variable e.g.HeaderLine. Then create a script task, put HeaderLine var in read/write variables and code it with:

System.IO.StreamReader file = 
   new System.IO.StreamReader(Dts.Connections["myfile"].ConnectionString);
Dts.Variables["HeaderLine"].Value = file.ReadLine();
file.Close();

That's pretty much it, then you can put a standard DataFlow to read filedata from file to DB or resultset.

You'll have the first line in HeaderLine variable, which you can use anywhere you want in the SSIS package.

makciook
  • 1,537
  • 10
  • 19