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

发布于 2024-12-11 22:03:09 字数 5901 浏览 0 评论 0原文

我是 SSIS 的新手,所以任何帮助、建议、意见和指导将不胜感激。谢谢。

场景

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

问题

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

DTS 代码(正确看待事物)

'********************* *************** *** ' Visual Basic ActiveX 脚本 '*********** *******< /em>***************< /em>********

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

I'm new to SSIS, so any help, suggestions, advice and guidance will be much appreciated. Thanks.

THE SCENARIO

I'm trying to convert a DTS package to an SSIS Package. My package contains a Data Flow task that pumps data from an OLE DB connection to a Flat File destination.

THE PROBLEM

The data in the flat file needs to be arranged in a certain way (eg: spacing), So how do I do that? Is there any data transformation tool that will help me achieve this? If so how would it be done?

THE DTS CODE (to put things in perspective)

'***************************************
' Visual Basic ActiveX Script
'*****************************************

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

护你周全 2024-12-18 22:03:09

我当然不会错过 DTS...

您在 SSIS 中寻找的是平面文件连接管理器并指定它的固定宽度(在高级中定义列)。让连接管理器确定大小的美妙之处在于,您只需设置一次就可以了,输出中不会出现任何相差一的错误,因为您搞乱了逻辑。 我从来没有这样做过

常规选项卡

平面文件连接管理器 - 常规选项卡

列选项卡

平面文件连接管理器 - 列选项卡

“高级”选项卡

平面文件连接管理器 - 高级选项卡

数据流看起来像

在此处输入图像描述

唯一的事情我不确定是否有 0 填充列。您可能需要使用派生列来填充这些列,但这应该不会太糟糕——只需将列大小填充为零,并使用需要警惕的常见 NULL 连接规则获取正确的 N 个字符即可。

I sure don't miss DTS...

What you're looking for in SSIS is a Flat File Connection Manager and specify it's Fixed Width (define the columns in Advanced). Beautiful thing about letting the connection manager determine size is you set it once and that's it, no off-by-one errors in the output because you flubbed the logic. not that I've ever done that

General tab

Flat File Connection Manager - General tab

Columns tab

Flat File Connection Manager - columns tab

Advanced tab

Flat File Connection Manager - Advanced tab

The Data Flow would look something like

enter image description here

The only thing I'm not sure about is the 0 padded columns. You might need to work with a derived column to fill those in but it shouldn't be too bad---just pad the column size of zeros and take the right N characters with the usual NULL concatenation rules to be wary of.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文