数据流任务中的增量变量
Increment Variables in Data Flow task
我有一个很大的文本文件,其中有多个不同的行。
我正在使用条件拆分,它会查看行类型(字段 1)然后执行操作,主要是尝试增加一个变量,将单行拆分为多列(派生),然后将结果写入table.
但是,当尝试增加变量时,我得到 "The collection of variables locked for read and write access is not available outside of PostExecute."
正在使用脚本组件更新变量。
我曾尝试将代码移动到 PostExecute,但在那个时候,它似乎永远不会增加。
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim MaximumKey As Int32 = Me.Variables.SPIParentID ' Grab value of MaxKey which was passed in
' NextKey will always be zero when we start the package.
' This will set up the counter accordingly
If (NextKey = 0) Then
' Use MaximumKey +1 here because we already have data
' and we need to start with the next available key
NextKey = MaximumKey + 1
Else
' Use NextKey +1 here because we are now relying on
' our counter within this script task.
NextKey = NextKey + 1
End If
'Row.pkAAAParentID = NextKey ' Assign NextKey to our ClientKey field on our data row
Me.Variables.SPIParentID = NextKey
End Sub
我希望能够使用我已有的条件拆分遍历文件,然后当它到达某个记录类型时,它将获取当前的 RecordTypeID 并递增它,然后写出到下一条记录.
SSIS 变量值不能在数据流任务中更改,该值在执行整个数据流任务后更改。任何时候你试图从这个变量中读取值,它都会 return 它的值,当数据流任务被执行时。您可以更改在脚本中使用局部变量来实现相同的逻辑:
Dim MaximumKey As Int32 = 0
Public Overrides Sub PreExecute()
MyBase.PreExecute()
MaximumKey = Me.Variables.SPIParentID ' Read the initial value of the variable
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
' NextKey will always be zero when we start the package.
' This will set up the counter accordingly
If (NextKey = 0) Then
' Use MaximumKey +1 here because we already have data
' and we need to start with the next available key
NextKey = MaximumKey + 1
Else
' Use NextKey +1 here because we are now relying on
' our counter within this script task.
NextKey = NextKey + 1
End If
'Row.pkAAAParentID = NextKey ' Assign NextKey to our ClientKey field on our data row
Me.Variables.SPIParentID = NextKey
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
Me.Variables.SPIParentID = MaximumKey ' Save the latest value into the variable
End Sub
我有一个很大的文本文件,其中有多个不同的行。
我正在使用条件拆分,它会查看行类型(字段 1)然后执行操作,主要是尝试增加一个变量,将单行拆分为多列(派生),然后将结果写入table.
但是,当尝试增加变量时,我得到 "The collection of variables locked for read and write access is not available outside of PostExecute."
正在使用脚本组件更新变量。
我曾尝试将代码移动到 PostExecute,但在那个时候,它似乎永远不会增加。
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim MaximumKey As Int32 = Me.Variables.SPIParentID ' Grab value of MaxKey which was passed in
' NextKey will always be zero when we start the package.
' This will set up the counter accordingly
If (NextKey = 0) Then
' Use MaximumKey +1 here because we already have data
' and we need to start with the next available key
NextKey = MaximumKey + 1
Else
' Use NextKey +1 here because we are now relying on
' our counter within this script task.
NextKey = NextKey + 1
End If
'Row.pkAAAParentID = NextKey ' Assign NextKey to our ClientKey field on our data row
Me.Variables.SPIParentID = NextKey
End Sub
我希望能够使用我已有的条件拆分遍历文件,然后当它到达某个记录类型时,它将获取当前的 RecordTypeID 并递增它,然后写出到下一条记录.
SSIS 变量值不能在数据流任务中更改,该值在执行整个数据流任务后更改。任何时候你试图从这个变量中读取值,它都会 return 它的值,当数据流任务被执行时。您可以更改在脚本中使用局部变量来实现相同的逻辑:
Dim MaximumKey As Int32 = 0
Public Overrides Sub PreExecute()
MyBase.PreExecute()
MaximumKey = Me.Variables.SPIParentID ' Read the initial value of the variable
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
' NextKey will always be zero when we start the package.
' This will set up the counter accordingly
If (NextKey = 0) Then
' Use MaximumKey +1 here because we already have data
' and we need to start with the next available key
NextKey = MaximumKey + 1
Else
' Use NextKey +1 here because we are now relying on
' our counter within this script task.
NextKey = NextKey + 1
End If
'Row.pkAAAParentID = NextKey ' Assign NextKey to our ClientKey field on our data row
Me.Variables.SPIParentID = NextKey
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
Me.Variables.SPIParentID = MaximumKey ' Save the latest value into the variable
End Sub