Saturday, January 9, 2016

Split multiple values in one field into rows in SSIS

In some cases, one filed might have multiple values with comma separated, you might need to normalized and make it as multiple records. In this situation, SSIS script component gives more flexibility to split into multiple records or normalize the records.
  public override void Input0_ProcessInputRow(Input0Buffer Row)
   {
       string s = Row.sscale;
       var primeArray = s.Split(',');
       int indice = 1;


       for (int i = 0; i < primeArray.Length; i += 1)
       {
           string value = primeArray[i];
           //value = value.Replace(",",".");
           Output0Buffer.AddRow();
           Output0Buffer.scalevalue = primeArray[i];
           Output0Buffer.idcartola = Row.idcartola;
           Output0Buffer.courseid = Row.course;
           Output0Buffer.scaleid = Row.idscale;
           Output0Buffer.scaleindex = indice;
           Output0Buffer.scalevalue = value;
           Output0Buffer.actid = Row.idact;
           Output0Buffer.moodleinst = instance;
               
               indice = indice + 1;

       }
Cheers!
Uma

1 comment:

  1. I feel this is the most useful and relatable blog post about SSIS and its related various aspects of those tools that are required to minimise redundant database operations.

    SSIS Postgresql Write



    ReplyDelete