【问题标题】:how to split the value with characters and numbers in SSIS如何在SSIS中用字符和数字拆分值
【发布时间】:2020-09-13 19:59:48
【问题描述】:

我在 SSIS 中读取的 excel 中有 ABC1234AB12CDFHY1234 等值,我需要将它们拆分为字母和数字。 如您所见,我们无法预测值中可能包含的数字字母。

请帮我想办法在 SSIS 中分别拆分它们。

感谢您的帮助。

【问题讨论】:

  • 具体来说,您是否正在寻找可以执行此操作的 SSIS 表达式?或者,T-SQL 中的某些东西会做吗?

标签: sql-server ssis etl


【解决方案1】:

首先,您必须在 DataFlowTask 中添加一个脚本组件,并在其中添加 2 个输出列。并将您的列标记为输入列。

其次,你必须使用脚本来拆分这个字符串值。

在你的脚本中声明这些函数

Private Shared Function GetNum(ByVal value As String) As Integer
    Dim mytext As String = String.Empty
    Dim myChars() As Char = Value.ToCharArray()
    For Each ch As Char In myChars
         If Char.IsDigit(ch) Then
              myText &= ch
         End If
    Next
    Return Cint(myText)
End Function


Private Shared Function GetText(ByVal value As String) As String
    Dim mytext As String = String.Empty
    Dim myChars() As Char = Value.ToCharArray()
    For Each ch As Char In myChars
         If Char.IsLetter(ch) Then
              myText &= ch
         End If
    Next
    Return myText
End Function

考虑您的输入列是inCol,而您的输出列是outNumoutText

If Row.inCol_IsNull = False Then
    Row.outText = GetText(Row.inCol)
    Row.outNum = GetNum(Row.inCol)
Else
    Row.outText_IsNull = True
    Row.outNum_IsNull = True
End If

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-01
    • 2018-04-23
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    相关资源
    最近更新 更多