【问题标题】:Split multi value column into multiple records将多值列拆分为多条记录
【发布时间】:2019-07-12 14:50:43
【问题描述】:

我正在尝试将多值列拆分为 ssis 脚本组件中的多个记录。我有一栏是演员的名字,另一栏是他们主演的电影(用逗号分隔)。现在我想拆分信息,以便每个 raw 包含演员的姓名和只有一部电影的标题。我正在使用下面的代码,但它有问题。有谁能够帮助我?

我使用我找到的代码,只是将 Input 和 Output 更改为 Cyrillic 以适应我的程序语言。

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: Ссылка на объект не указывает на экземпляр объекта。

【问题讨论】:

标签: vb.net ssis split etl script-component


【解决方案1】:

在使用前检查输入列是否为 Null:

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

【讨论】:

  • 谢谢!问题在于,正如您所建议的,其中一列中有 NULL。
猜你喜欢
  • 2022-12-05
  • 2022-10-14
  • 2013-07-16
  • 1970-01-01
  • 2011-05-10
  • 2022-12-09
  • 2022-11-10
  • 2016-11-21
  • 2016-11-12
相关资源
最近更新 更多