How to Generate an Auto Incremental Number in a SSIS Package?

1. Drag and drop the Script Component to the Data flow and select Script Component Type as Transformation. 2. Double click the Script Component.
3. In the Input Columns tab, select the column you want to pass through the script component.
4. In the Inputs and Outputs tab, add a column with an integer data type. (In this sample below, I have added a column name Column.)


5. Next, go to the Script tab and click the Design Script button. Type the following script in the script editor:

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper Public Class ScriptMain
    Inherits UserComponent     Dim intCounter As Integer = 0 ‘Set intial value here
    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
         Row.Column = intCounter
         intCounter = intCounter + 1   ‘ Set the incremental value here
    End Sub
End Class In the above script you can set the initial value and the incremental value to whatever you want. In the above example both are set to 1. 6. The following is the output of the script in which the column named Column is the auto incremental field generated from the Script Component.



Leave a comment

Your email address will not be published.