robthomas09
asked on
SSIS Package - exporting text file - Visual Studio
Hello experts,
I have Microsoft Visual Studio 2012 with SSIS tools installed, and I currently have a package that is harvesting data from a few tables in the database via SQL script, but ultimately compiling and outputting in CSV format to a text file with headers.
Looks something like this in the output:
person_id file_id location_id
12345 NG1234 1234567890
12345 NG1235 1234567891
12346 NG1236 1234567892
12346 NG1237 1234567893
That works just fine but I recently received a request to have a 1-time bit of text at the top before the CSV file data floods in, mostly header information. I would like to find a way to have the file out put be:
user:testuser
password:uf43ufn4u
api_id:34593434
text:Hello #field1#, your account balance is now #field2# as of 12:00AM today.
delimiter:|
person_id file_id location_id
12345 NG1234 1234567890
12345 NG1235 1234567891
12346 NG1236 1234567892
12346 NG1237 1234567893
The chunk of text at the top, right before the CSV person_id text starts, would be static and never changing believe it or not.
Thoughts?
Thanks!
I have Microsoft Visual Studio 2012 with SSIS tools installed, and I currently have a package that is harvesting data from a few tables in the database via SQL script, but ultimately compiling and outputting in CSV format to a text file with headers.
Looks something like this in the output:
person_id file_id location_id
12345 NG1234 1234567890
12345 NG1235 1234567891
12346 NG1236 1234567892
12346 NG1237 1234567893
That works just fine but I recently received a request to have a 1-time bit of text at the top before the CSV file data floods in, mostly header information. I would like to find a way to have the file out put be:
user:testuser
password:uf43ufn4u
api_id:34593434
text:Hello #field1#, your account balance is now #field2# as of 12:00AM today.
delimiter:|
person_id file_id location_id
12345 NG1234 1234567890
12345 NG1235 1234567891
12346 NG1236 1234567892
12346 NG1237 1234567893
The chunk of text at the top, right before the CSV person_id text starts, would be static and never changing believe it or not.
Thoughts?
Thanks!
ASKER
Thanks for the reply!
Not being the strongest at .NET, I will do some research and give that a try for sure. I did see that you mentioned "There are many ways to do this" - any chance on elaborating on a few of the others in case I might be stronger-suited in in one of those manners?
Thanks again!
Not being the strongest at .NET, I will do some research and give that a try for sure. I did see that you mentioned "There are many ways to do this" - any chance on elaborating on a few of the others in case I might be stronger-suited in in one of those manners?
Thanks again!
ASKER
No luck any other ideas?
ASKER
Something like:
public override void PostExecute()
{
base.PostExecute();
System.IO.StreamWriter tw
= System.IO.File.AppendText( @"C:\Test. txt");
tw.WriteLine("Text at the top of the file");
base.ProcessInput(InputID, Buffer);
tw.Close();
}
public override void CreateNewOutputRows()
{
}
}
public override void PostExecute()
{
base.PostExecute();
System.IO.StreamWriter tw
= System.IO.File.AppendText(
tw.WriteLine("Text at the top of the file");
base.ProcessInput(InputID,
tw.Close();
}
public override void CreateNewOutputRows()
{
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
paid someone to fix this for me, with .NET skills
1) after the data flow task at the end of your package, put a script compoenent.
And in the script by using the .NET runtime open the file and add the text to the start of it -- pretty easy task -- but not appealing to tech geeks.