String manipulations with the SSIS Script Component

Problem: Your source data contains a column that should be split in two. In this case there is a name column in an Excel file that contains both the first and last name. The destination database has the first and last name as separate columns.

Excel Sample

Solution: Use the script the component and split apart the column data into a string array.

Step I: In a Data Flow add an Excel source and then add a Script Component with the component type “Transformation.” Add a First Name, Middle Name and Last Name as column outputs. Be sure to add the name column from the source data as an input column.

Add Script Component

Data Flow View

Output Columns

Step II: Open the script editing window and edit the ProcessInputRow method. In this example were going to assume that each name is separated by a space. Using the String.Split() method, break up the name column into a string array. If the array length is 3, then we have a first, last and middle name. If the array length is only 2, then only the first and last name is present.

Step III: Assign the output columns with the appropriate item from the index.

public class ScriptMain : UserComponent
{

    public override void InputCustomers_ProcessInputRow(InputCustomersBuffer Row)
    {
        var names = Row.Name.Split(‘ ‘);

        //if lenght is two, not middle skip the middle name
        if (names.Length == 2)
        {
            Row.FirstName = names[0];
            Row.LastName = names[1];
        }
        else if (names.Length == 3)
        {
            Row.FirstName = names[0];
            Row.MiddleName = names[1];
            Row.LastName = names[2];
        }

    }
}

We now have three columns ready to be passed to the destination data source.

Data view

String manipulations with the SSIS Script Component
Posted in Data Integration, SSIS, Uncategorized | Tagged , | Comments Off

XML and Me

Starting with the Spring Semester at Northwestern Michigan College, I will be teaching an introductory course in XML (CIT 185 – XML Programming).

Teaching in some capacity has been an item in my “bucket list” for some time. So I am excited to begin sharing the love with XML, XSLT, XQuery and friends. And teaching at NMC has special significance. Fourteen years ago when I was just starting out in the IT world I took a database course at NMC. Now I hope to help someone else get started as a programmer.

Posted in Uncategorized | Leave a comment