2012-09-12 24 views
0

我有幾個CSv輸入文件以及不同的文件名以及不同的日期格式。我需要根據條件動態選擇輸入文件。根據SSIS變量表達式中的條件添加輸入文件名稱

例如

i have files file120120909.csv, scalefile09102012.csv 

我需要以檢索基於條件的輸入文件。所以我已經邁出了用戶變量,並以這種方式表達返回

(@[User::Type] =="File" ? "file" : (@[User::type] =="scale" ? "scale_" :"NA")) + (DT_STR,4,1252)DATEPART("yyyy", @[System::StartTime]) + RIGHT("0" + (DT_STR,2,1252) DATEPART("mm", @[System::StartTime]),2) + RIGHT("0" + (DT_STR,2,1252)DATEPART("dd", @[System::StartTime]),2) 

當我評估我得到了以下結果

file120120912 

現在,當我的用戶變量@ [用戶賦值表達式::鍵入] ==「比例」,那麼表達結果必須是scalefile09102012

因此,基於條件我如何可以追加該文件的日期

回答

0

你可以寫VB.NET代碼到腳本任務,以解決您的問題:

Dim type As String = Dts.Variables("Type").Value.ToString() 
    Dim startDate As DateTime = DateTime.Parse(Dts.Variables("StartTime").Value.ToString()) 

    Dim result As String = "" 

    If type.ToLower() = "file" Then 
     result = type.ToLower() + startDate.ToString("yyyyMMdd") 
    ElseIf type.ToLower() = "scale" Then 
     result = type.ToLower() + "file" + startDate.ToString("MMddyyyy") 
    Else 
     result = "incorrect type" 
    End If 

    MsgBox(result)