How can I use SSIS to add an extra column containi

2019-06-21 01:28发布

问题:

I have this SSIS workflow defined. After I explain what I'm doing, it might be possible my approach is wrong, as this is my first "real" SSIS package.

To increment the counter I do this:

public void Main()
{
    int i = Convert.ToInt32(Dts.Variables["User::DayCounter"].Value.ToString());
    i++;
    Dts.Variables["User::DayCounter"].Value = i;

    Dts.TaskResult = (int)ScriptResults.Success;
}

My destination table currently looks like this:

PID Campaign Name   Company Impr    Clicks  Clickthru   Leads   View-Through Leads  # Sales # View-Through Sales    Sales   View-Through Sales  Sub Sales   View-Through Sub Sales  We Get  They Get    Revenue EPC S U R T Active  SourceFile
1734    US - Lending Tree Refinance Mortgage - DA 3 Page SSN    Tree.com    58  2,053   3,539.66%   201 0   0   0    0.00    0.00    0.00    0.00    8044.02     5846.00     2198.02     2.85   10% Yes Active  \\ad1\Marketing\Aaron\DirectTrackAutomatedReports\admin_program_stats_20120229.csv

My goal is simply to add a column called Day to the report, containing the value of the counter variable.

回答1:

You should add a Derived Column transformation in your Data Flow task between the Flat File Source and OLE DB Destination components.

The Derived Column transformation will add a new column called Day based on your variable.

After that a new Day column will be presented in the data flow. Just map this column to your corresponding database field. (Assume there is a Day column in your report table.)