Domanda

Is there any way to keep a running count of a number using a local/global variable within the ProcessInputRow function in a SSIS Component Script?

for example:

Row1: 1
Row2: 1
Row3: 0

So say the variable is set default = 0

After row 1, the variable will now be = 1

After row 2, the variable will now be = 2

After row 3, the variable will now be = 1

Since the ProcessInputRow function processes each input row individually, it resets my local variables, and you can't use SSIS user created variables outside of PostExecute(), I am at a loss here.

È stato utile?

Soluzione

 private int count = 0;
  public override void PreExecute()
{
   base.PreExecute();
   //some code where you can increment count
}

public override void PostExecute()
{
    base.PostExecute();
    // Count it accessible here as well 
}

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    //Count will be accessible but not reset here
}

Let me know if this answers your question

Altri suggerimenti

It's actually quite simple - use a member variable (also known as a field) in your Script component's ScriptMain class:

/* Microsoft SQL Server Integration Services Script Component
*  Write scripts using Microsoft Visual C# 2008.
*  ScriptMain is the entry point class of the script.*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    private int _myVariable = 0;

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        Row.SomeValue = _myVariable;
        _myVariable = Row.SomeOtherValue;

    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top