Split a single column of data with comma delimiters into multiple columns in SSIS

后端 未结 2 739
暗喜
暗喜 2020-12-06 20:39

I have a table in SQL Server with 3 columns, one of which is a data column containing rows of concatenated columns delimited by commas. The first row is also the header row

2条回答
  •  旧巷少年郎
    2020-12-06 21:19

    What you can do is to read the file as is. And Split those values in a script task.

    So from source go to a script task. Then in the script task as input column, select the column containing those values (InputColumn1). Then specify the output columns (If I am right I see you have 5, so specify 5 (OutputColumn1 - 5)).

    After that is done, go to the script itself (C#).

    Under:

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
    }
    

    Put the following code in there:

    var ColumnValue = Row.InputColumn1.Split(',');
    
    Row.OutputColumn1 = ColumnValue[0];
    Row.OutputColumn2 = ColumnValue[1];
    Row.OutputColumn3 = ColumnValue[2];
    Row.OutputColumn4 = ColumnValue[3];
    Row.OutputColumn5 = ColumnValue[4];
    

    After the script task all the columns from the Source as well as the OutputCoulmns1-5 will be available and you can do what you have to.

    OUTPUT

     Data      | ID | Source |OutputColumn1 |OutputColumn2|  etc. 3-5
     ================================================================
     a,b,c,d,e | 1  | a.csv  |  a           |  b
    
     f,g,h,i,j | 2  | b.csv  |  f           |  g
    

    Please ask if something is not clear.

提交回复
热议问题