Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use SSIS to add an extra column containing the value of an incremented variable into my destination table?

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.

enter image description here

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.

like image 861
Aaron Anodide Avatar asked Mar 01 '12 04:03

Aaron Anodide


People also ask

How do I add more columns in SSIS?

Derived Columns Grid Derived Column Name: Specify the derived column name. Derived Column: Select between <add new column> and <replace an existing column> options. Expression: Write the SSIS expression that produce the derived column. Data Type: This column is read-only and it shows the data type of the expression ...

How do you increment value in SSIS?

Steps to generate an Auto Incremental Number in SSIS package: - Drag the Script component to the Data flow and select Script component type as Transformation. - Double click the script component. In the input columns tab choose the column you need to pass through script component.


1 Answers

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

Add Derived Column transformation

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

New column

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.)

like image 54
luviktor Avatar answered Nov 04 '22 10:11

luviktor