SSIS平面文件目标导出多行列

时间:2017-04-11 10:13:23

标签: sql-server ssis etl bids flat-file

我有一个SQL表作为Source,我想使用SSIS将它的内容导出到一个Flat文件。

简化示例:

$(function() {
    $(".AddItem").click(function() {
  $(this).closest('table').find('tr:last').prev().after('<tr><td><select type="select" class="custom-select custom-select_gray" data-toggle="dropdown" id="dropdownMenuAdded" aria-haspopup="true" aria-expanded="true" style="font-family: \'Work Sans\', Tahoma, Geneva, sans-serif;font-size:10px;color:#606060;text-align:center;width:100px;height:25px;"><option label="Event">Event</option></select></td></tr>');
  addOptions();
        return false;
    });
});
function addOptions(){
var events = [[ "Event 1", "10.04"], [ "Event 2", "30.04"]];
var selId = "dropdownMenuAdded";


initDropdownList(selId, events);
}
function initDropdownList( id, eventEls ) {
    var select, i, option;

    select = document.getElementById( id );
    for ( i = 0; i < eventEls.length; i++ ) {
        option = document.createElement( 'option' );
        /* alert("eventEls.length: " + eventEls.length);
        alert("eventEls[i]: " + eventEls[i][0] + " " + eventEls[i][1]);*/
        option.value = option.text = eventEls[i][0] + " " + eventEls[i][1];
        select.add( option );
    }
    select.id = "dropdownMenu1";
}

$(function() {
    $(".AddOption").click(function() {


});
});

问题是描述可能很长,我们不希望在Source: Notes table (CreatedBy, Description, CreatedOn) The Description field is nText. Destination: Flat file - Fixed length CreatedBy(0-50) Description (51-250) CreatedOn (251-270) 字符之后将其截断。它应该换行到下一行。

我找不到使用SSIS的方法。

非常感谢您的帮助。

更新

我希望实现如下布局:

200

Hadi的答案允许将长字符串分成几部分,但仍然无法解决布局问题。

1 个答案:

答案 0 :(得分:1)

您必须按照以下步骤操作:

  1. DataFlow TaskOLEDB Source

  2. 之间的Flat File Destination添加s脚本组件中
  3. Script Component标记Description列作为输入,将OutDescription列添加为类型DT_WSTR和长度200

  4. Script窗口中输入以下代码(内部Input0_RowProcessing方法:

    If Not Row.Description_IsNull AndAlso 
       Not String.IsNullOrEmpty(Row.Description.Trim) Then
    
           If Row.Description.Trim.Length > 200 Then
    
                Dim LongString As String = Row.Description.Trim
    
                Dim longlist As New System.Collections.Generic.List(Of String)
    
                Dim idx As Integer = 0
    
                While idx <= LongString.Length
    
                    If LongString.Length < idx + 200 Then
                        longlist.Add(LongString.Substring(idx))
                    Else
                        longlist.Add(LongString.Substring(idx, 200))
                    End If
    
    
    
                    idx += 200
    
                End While
    
                Row.OutDescription = String.Join(vbNewLine & "".PadLeft(50,CChar(" ")), longlist)
    
           Else
    
               Row.OutDescription = Row.Description
    
            End If
    
    Else
    
    
        Row.OutDescription_IsNull = True
    
    
    End IF
    
  5. Flat File Destination地图OutDesciption列而不是Description

相关问题