将多值列拆分为多条记录
Split multi value column into multiple records
我正在尝试在 ssis 的脚本组件中将多值列拆分为多条记录。我有一列是演员的名字,另一列是他们主演的电影(用逗号分隔)。现在我想拆分信息,以便每个原始文件只包含演员的姓名和一部电影的标题。我正在使用下面的代码,但它有问题。有谁能够帮我?
我使用找到的代码,只是将输入和输出更改为西里尔字母以适应我的程序语言。
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
Public Overrides Sub Вход0_ProcessInputRow(ByVal Row As Вход0Buffer)
' This array would hold the single numeric values after you tokenize the input column '
Dim inputNumericValuesArray As Array
' This varibale would hold one value from the array during the loop '
Dim currentNumericValue As String
' Tokenize the NumericValues column by splitting it based on a semicolon separator '
inputNumericValuesArray = Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles.Split(","c)
' Loop on the retrieved tokens adding each in a new row '
For Each currentNumericValue In inputNumericValuesArray
' Create a new row '
Выход0Buffer.AddRow()
' Get the TaskName from the source row and assign it to the output row without any changes '
Выход0Buffer.nconst = Row.ПреобразованиеданныхПреобразованиевЮникодnconst
' Parse the current numeric value as decimal '
' and assign it to the Numeric value of the output row '
Выход0Buffer.knownForTitle = Decimal.Parse(currentNumericValue)
Next
End Sub
End Class
错误是0xC0047062
。错误的完整描述如下:
Ошибка: 0xC0047062 в Заполнение name_title 1 1, Компонент скриптов
[23]: System.NullReferenceException: Ссылка на объект не указывает на
экземпляр объекта.
在使用之前简单地检查输入列是否为空:
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
Public Overrides Sub Вход0_ProcessInputRow(ByVal Row As Вход0Buffer)
' This array would hold the single numeric values after you tokenize the input column '
Dim inputNumericValuesArray As Array
' This varibale would hold one value from the array during the loop '
Dim currentNumericValue As String
If Not Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles_IsNull Then
' Tokenize the NumericValues column by splitting it based on a semicolon separator '
inputNumericValuesArray = Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles.Split(","c)
' Loop on the retrieved tokens adding each in a new row '
For Each currentNumericValue In inputNumericValuesArray
' Create a new row '
Выход0Buffer.AddRow()
' Get the TaskName from the source row and assign it to the output row without any changes '
If Not Row.ПреобразованиеданныхПреобразованиевЮникодnconst_IsNull Then
Выход0Buffer.nconst = Row.ПреобразованиеданныхПреобразованиевЮникодnconst
Else
Выход0Buffer.nconst)IsNull = True
End If
' Parse the current numeric value as decimal '
' and assign it to the Numeric value of the output row '
Выход0Buffer.knownForTitle = Decimal.Parse(currentNumericValue)
Next
End If
End Sub
End Class
我正在尝试在 ssis 的脚本组件中将多值列拆分为多条记录。我有一列是演员的名字,另一列是他们主演的电影(用逗号分隔)。现在我想拆分信息,以便每个原始文件只包含演员的姓名和一部电影的标题。我正在使用下面的代码,但它有问题。有谁能够帮我?
我使用找到的代码,只是将输入和输出更改为西里尔字母以适应我的程序语言。
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
Public Overrides Sub Вход0_ProcessInputRow(ByVal Row As Вход0Buffer)
' This array would hold the single numeric values after you tokenize the input column '
Dim inputNumericValuesArray As Array
' This varibale would hold one value from the array during the loop '
Dim currentNumericValue As String
' Tokenize the NumericValues column by splitting it based on a semicolon separator '
inputNumericValuesArray = Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles.Split(","c)
' Loop on the retrieved tokens adding each in a new row '
For Each currentNumericValue In inputNumericValuesArray
' Create a new row '
Выход0Buffer.AddRow()
' Get the TaskName from the source row and assign it to the output row without any changes '
Выход0Buffer.nconst = Row.ПреобразованиеданныхПреобразованиевЮникодnconst
' Parse the current numeric value as decimal '
' and assign it to the Numeric value of the output row '
Выход0Buffer.knownForTitle = Decimal.Parse(currentNumericValue)
Next
End Sub
End Class
错误是0xC0047062
。错误的完整描述如下:
Ошибка: 0xC0047062 в Заполнение name_title 1 1, Компонент скриптов [23]: System.NullReferenceException: Ссылка на объект не указывает на экземпляр объекта.
在使用之前简单地检查输入列是否为空:
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
Public Overrides Sub Вход0_ProcessInputRow(ByVal Row As Вход0Buffer)
' This array would hold the single numeric values after you tokenize the input column '
Dim inputNumericValuesArray As Array
' This varibale would hold one value from the array during the loop '
Dim currentNumericValue As String
If Not Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles_IsNull Then
' Tokenize the NumericValues column by splitting it based on a semicolon separator '
inputNumericValuesArray = Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles.Split(","c)
' Loop on the retrieved tokens adding each in a new row '
For Each currentNumericValue In inputNumericValuesArray
' Create a new row '
Выход0Buffer.AddRow()
' Get the TaskName from the source row and assign it to the output row without any changes '
If Not Row.ПреобразованиеданныхПреобразованиевЮникодnconst_IsNull Then
Выход0Buffer.nconst = Row.ПреобразованиеданныхПреобразованиевЮникодnconst
Else
Выход0Buffer.nconst)IsNull = True
End If
' Parse the current numeric value as decimal '
' and assign it to the Numeric value of the output row '
Выход0Buffer.knownForTitle = Decimal.Parse(currentNumericValue)
Next
End If
End Sub
End Class