SSIS Package to get flat file output with appended lines

Subhomoy Chakraborty 106 Reputation points
2023-02-15T09:47:11.5466667+00:00

Hi Team,

Please find the attached file in which format I need the output through SSIS package.

20220425_130201_Dop_Test.txt

As of now through SQL procedure I am able to get the header and corresponding data but unable to append the other lines. Please let me know the way how top append the other lines in any way through SSIS.

1st Line : Test Financial Data.

2nd Line : <Blank>

3rd Line : the header names as mentioned (Coming from SQL procedure)

4th Line : ----------------------+--------------------------------+-----

Then the data will come from the table as mentioned ()(Coming from SQL procedure)

Then the no of rows.

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,703 questions
SQL Server | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Seth Lynch 0 Reputation points
    2023-02-15T13:46:16.36+00:00

    You should add a Data Flow Task to your SSIS project. Inside the DFT go to other sources and select a Flat File source. When you define the connection you can specify that it skip the first 4 rows and import data from row 5. You should be able to test this by using the preview


  2. ZoeHui-MSFT 41,491 Reputation points
    2023-02-16T02:42:53.06+00:00

    Hi @subhomoy chakraborty

    You may first use DFT to load the data from SQL procedure to txt file temporarily.

    And then add Script Task to add the three lines with the C# code like below.

    string filePath = "C:\\Users\\Administrator\\Desktop\\test.txt";
                List<string> lines = new List<string>();
                if (File.Exists(filePath))
                {
                    lines = File.ReadAllLines(filePath).ToList();
                }
                lines.Insert(1, "-------------------------------------------");
                string newContent="Test Financial Data."+Environment.NewLine+Environment.NewLine;   
                File.WriteAllText(filePath, newContent + string.Join("\r",lines));
    
    

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.