如何在ssis使用脚本组件中将单个记录拆分为多个记录

时间:2014-08-19 11:24:28

标签: ssis

我有像

这样的记录
pid  pname sal  Loc
1    A      300  hyd

我想输出

pid    pname    sal    loc
1       A       0       0
1       0       300     0
1       0       0       hyd

我们怎样才能在ssis中做到这一点

1 个答案:

答案 0 :(得分:0)

这是我如何得到你想要的输出。将脚本组件拖到设计图面上,然后选择转换。确保将源组件的输出连接到此脚本组件。在“输入和输出”选项卡上,单击“输出0”,在“公共属性”部分中,您将看到名为SynchronousInputId的属性,将其值更改为“无”。 现在,在输出0中,为通过管道的每个列添加输出列,并使用适当的数据类型,即pid,pname,sal和loc。

然后将此C#代码复制到main:

 #region Namespaces
 using System;
 using System.Data;
 using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
 using Microsoft.SqlServer.Dts.Runtime.Wrapper;
 #endregion

    [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
    public class ScriptMain : UserComponent
    {
        public override void Input0_ProcessInputRow(Input0Buffer Row)
        {

            //Generate records for each pid
            for (int i = 0; i < 3; i++)
            {
                switch (i)
                {
                    case 0:
                        Output0Buffer.AddRow();
                        Output0Buffer.pid = Row.pid;
                        Output0Buffer.pname = Row.pname;
                        Output0Buffer.sal = 0;
                        Output0Buffer.loc = "0";
                        break;
                    case 1:
                        Output0Buffer.AddRow();
                        Output0Buffer.pid = Row.pid;
                        Output0Buffer.pname = "0";
                        Output0Buffer.sal = Row.sal;
                        Output0Buffer.loc = "0";
                        break;
                    case 2:
                        Output0Buffer.AddRow();
                        Output0Buffer.pid = Row.pid;
                        Output0Buffer.pname = "0";
                        Output0Buffer.sal = 0;
                        Output0Buffer.loc = Row.loc;
                        break;

                }



            }


        }

    }

确保在关闭和保存之前构建此代码。

相关问题