使用SSIS,如何在从OLE DB源中抽取的平面文件目标中排列数据

时间:2011-10-25 09:03:13

标签: vb.net sql-server-2008 ssis dts

我是SSIS的新手,所以非常感谢任何帮助,建议,建议和指导。感谢。

情景

我正在尝试将DTS包转换为SSIS包。我的包中包含一个数据流任务,用于将数据从OLE DB连接泵送到平面文件目标。

问题

平面文件中的数据需要以某种方式排列(例如:间距),那我该怎么做呢?是否有任何数据转换工具可以帮助我实现这一目标?如果是这样,怎么办呢?

DTS代码(以透视的方式)

“的 * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** 'Visual Basic ActiveX脚本 “的 ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * **

DO WHILE NOT  rsGetActivations.eof OR rsGetActivations.BOF
    sLineItem = Space(10)
    sLineItem = sLineItem & Space(10)
    sLineItem = sLineItem & Space(10)
    sLineItem = sLineItem & Replace(Space(8)," ","0")
    sLineItem = sLineItem & Space(1)
    sLineItem = sLineItem & Replace(Space(8)," ","0")
    sLineItem = sLineItem & Replace(Space(3)," ","0")
    sLineItem = sLineItem & Space(2)
    sLineItem = sLineItem & rsGetActivations("Data_Date") & Space( 8 - Len(  rsGetActivations("Data_Date") ) )
    sLineItem = sLineItem & rsGetActivations("ID_Number") & Space( 16 - Len(  rsGetActivations("ID_Number") ) )
    sLineItem = sLineItem & Space(4)
    sLineItem = sLineItem & rsGetActivations("Main_Name") & Space( 25 - Len(  rsGetActivations("Main_Name") ) )
    sLineItem = sLineItem & rsGetActivations("First_Name")  &  Space( 15 - Len(  rsGetActivations("First_Name") ) )
    sLineItem = sLineItem & rsGetActivations("Middle_Name")  & Space( 15 - Len(  rsGetActivations("Middle_Name") ) ) 
    sLineItem = sLineItem & rsGetActivations("Third_Name") & Space( 15 - Len(  rsGetActivations("Third_Name") ) )  
    sLineItem = sLineItem & rsGetActivations("DOB") & Space( 8 - Len(  rsGetActivations("DOB") ) )
    sLineItem = sLineItem & rsGetActivations("ID_Number") & Space( 13 - Len(  rsGetActivations("ID_Number") ) )
    sLineItem = sLineItem & rsGetActivations("Non_RSA_ID") & Space( 16 - Len(  rsGetActivations("Non_RSA_ID") ) )
    sLineItem = sLineItem & Space(15)
    sLineItem = sLineItem & Space(15)
    sLineItem = sLineItem & Space(15)
    sLineItem = sLineItem & Space(15)
    sLineItem = sLineItem & rsGetActivations("Gender") & Space( 1 - Len(  rsGetActivations("Gender") ) )
    sLineItem = sLineItem & Space(3)
    sLineItem = sLineItem & Space(1)
    sLineItem = sLineItem & Space(15)
    sLineItem = sLineItem & Space(15)
    sLineItem = sLineItem & Space(40)
    sLineItem = sLineItem & "0"
    sLineItem = sLineItem & rsGetActivations("Res_Line1")  & Space( 30 - Len(  rsGetActivations("Res_Line1") ) )  
    sLineItem = sLineItem & rsGetActivations("Res_Line2") & Space( 30 - Len(  rsGetActivations("Res_Line2") ) )  
    sLineItem = sLineItem & rsGetActivations("Res_Line3") & Space( 30 - Len(  rsGetActivations("Res_Line3") ) )  
    sLineItem = sLineItem & rsGetActivations("Res_Line4") & Space( 30 - Len(  rsGetActivations("Res_Line4") ) )  
    sLineItem = sLineItem & rsGetActivations("Res_Postal") & Space( 6 - Len(  rsGetActivations("Res_Postal") ) )
    sLineItem = sLineItem & Space(1)
    sLineItem = sLineItem & "00"
    sLineItem = sLineItem & Space(1)
    sLineItem = sLineItem & rsGetActivations("Post_Line1")  & Space( 30 - Len(  rsGetActivations("Post_Line1") ) )  
    sLineItem = sLineItem & rsGetActivations("Post_Line2") & Space( 30 - Len(  rsGetActivations("Post_Line2") ) )  
    sLineItem = sLineItem & rsGetActivations("Post_Line3") & Space( 30 - Len(  rsGetActivations("Post_Line3") ) )  
    sLineItem = sLineItem & rsGetActivations("Post_Line4") & Space( 30 - Len(  rsGetActivations("Post_Line4") ) )  
    sLineItem = sLineItem & rsGetActivations("Post_Postal") & Space( 6 - Len(  rsGetActivations("Post_Postal") ) )      
    sLineItem = sLineItem & Space(1)
    sLineItem = sLineItem & "00"
    sLineItem = sLineItem & rsGetActivations("Bank_Name") & Space( 20 - Len(  rsGetActivations("Bank_Name") ) )
    sLineItem = sLineItem & rsGetActivations("Bank_Branch") & Space( 20 - Len(  rsGetActivations("Bank_Branch") ) )
    sLineItem = sLineItem & Space( 6 - Len(  rsGetActivations("Branch_No") ) )  & rsGetActivations("Branch_No") 
    sLineItem = sLineItem & Space( 15 - Len(  rsGetActivations("Account_No") ) ) & rsGetActivations("Account_No")
    sLineItem = sLineItem & rsGetActivations("Home_Code") & Space( 11 - Len(  rsGetActivations("Home_Code") ) )
    sLineItem = sLineItem & rsGetActivations("Home_Tel") & Space( 15 - Len(  rsGetActivations("Home_Tel") ) )
    sLineItem = sLineItem & rsGetActivations("Work_Code") & Space( 11 - Len(  rsGetActivations("Work_Code") ) )
    sLineItem = sLineItem & rsGetActivations("Work_Tel") & Space( 15 - Len(  rsGetActivations("Work_Tel") ) )   
    sLineItem = sLineItem & rsGetActivations("Cell_No") & Space( 10 - Len(  rsGetActivations("Cell_No") ) )
    sLineItem = sLineItem & Space(35)
    sLineItem = sLineItem & rsGetActivations("Occupation")  & Space( 22 - Len(  rsGetActivations("Occupation") ) )  
    sLineItem = sLineItem & rsGetActivations("Emp_Name") & Space( 35 - Len(  rsGetActivations("Emp_Name") ) )       
    sLineItem = sLineItem & Space(2)
    sLineItem = sLineItem & Space(6)        

    fExportFile.Write(  sLineItem & sCRLF )

    rsGetActivations.MoveNext
LOOP'//end WHILE NOT  rsGetActivations.eof OR rsGetActivations.BOF

1 个答案:

答案 0 :(得分:0)

我肯定不会错过DTS ......

您在SSIS中寻找的是平面文件连接管理器,并指定它的固定宽度(在高级中定义列)。让连接管理器确定大小的美妙之处在于你设置了一次,就是这样,输出中没有一个错误的错误,因为你歪曲了逻辑。 并非我曾经那样做过

常规标签

Flat File Connection Manager - General tab

列标签

Flat File Connection Manager - columns tab

高级标签

Flat File Connection Manager - Advanced tab

数据流看起来像

enter image description here

我唯一不确定的是0填充柱。您可能需要使用派生列来填充它们,但它不应该太糟糕 - 只需填充零的列大小并使用通常的NULL连接规则获取正确的N个字符以保持警惕。