2017-05-06 76 views
2

我有類似的東西:SSIS - 移動XML文件到相應的文件夾取決於條件性拆分結果

Control Flow

和數據流以下代碼:

Data flow

我試圖參數化輸出變量中的輸出參數。 因此,例如

  • 當國家在XML文件是英國 - >動的XML文件到文件夾C:\ A
  • 當國家在XML文件不是英國 - >動的XML文件到文件夾C:\乙

也許我需要使用腳本組件?

這個輸出變量,我想放在文件系統任務目標字段,

有人能幫忙嗎?

+0

在問你的第一個問題之前最好採取[Stackover Flow Tour](http://stackoverflow.com/tour) – Hadi

回答

1

首先,您不必在條件拆分中創建Case 2,您可以使用默認輸出。 (因爲如果Case 1是假的行會被重定向到有條件拆分默認輸出)

你可以使用一個腳本組件在整個過程無需有條件拆分

只要做到以下幾點:

假設你存儲在一個名爲變量中的XML文件路徑User::XmlPath

  1. 刪除條件性拆分和兩個腳本組件,也刪除該文件系統任務
  2. 添加直接鏈接到XML源腳本組件
  3. 添加User::XmlPath到腳本組件ReadOnlyVariables

enter image description here

  1. 在腳本組件中寫入以下代碼

    Dim strPath As String = String.Empty 
    Public Overrides Sub PreExecute() 
        MyBase.PreExecute() 
    
        strPath = Variables.XmlPath 
        ' 
    End Sub 
    
    ' This method is called after all the rows have passed through this component. 
    ' 
    ' You can delete this method if you don't need to do anything here. 
    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) 
    
        Dim strFile As String = IO.Path.GetFileName(strPath) 
    
        If Row.Country.ToUpper = "UK" Then 
    
         IO.File.Move(strPath, "C:\A\" & strFile) 
    
        Else 
    
         IO.File.Move(strPath, "C:\B\" & strFile) 
    
        End If 
    
    End Sub 
    
相關問題