You have to do this in two steps:
1 - Read Max ID from SQL and store it into a variable
First of all you have to use an Execute SQL Task to read the Max ID from SQL Table into a variable. You can refer to the following article for a step by step guide:
2 - Increment the ID for each Row using a Script Component
After storing Max ID in a variable (example: @[User::MaxID]
), you have to use a Script Component inside a Data Flow Task to increment it for each row.
Add a Script Component Transfromation inside the Data Flow Task, select User::MaxID
as ReadOnly variable, add an output column (NewID) and use a similar Script (example in VB.NET)
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute> _
<CLSCompliant(False)> _
Public Class ScriptMain
Inherits UserComponent
Private CurrentID as Integer = 0
Public Overrides Sub PreExecute()
Base.PreExecute()
CurrentID = Dts.Variables.Item("User::MaxID").Value
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
CurrentID += 1
Row.NewID = CurrentID
End Sub
End Class
Similar posts