Sunday, May 6, 2012

SSIS 2012 - New expression language functions(ReplaceNull,Left, Token, TokenCount)

SQL Server 2012 is full rich of new features for SSIS, really many new useful stuff, such as the script task debug and the renovated Flat File Source, that could handle uneven number of columns...

Today I am going to demonstrate 4 new SSIS expression functions...

Which exactly the opposite of the RIGHT functions, and similar to the LEFT function in T-SQL, which allows you to grab a number of characters from your string, starting at point zero or in other words from the LEFT side of the string.
Which as the name means, it replaces your NULL values, with another string expression.  Before you would use ISNULL which returns Boolean injunction with a condition to change the value. ISNULL(LastName) ? "Unknown last name":LastName
3- TokenCount
Which allows you to separate your string into tokens based on a specified delimiter, and returns back the numbers of occurrence of that expressions (Number of Tokens)
Substrings your string into Tokens based on a specified delimiter and brings back the number of requested token.
Let's use a demo as I learn better by examples...

The demo script as following..will create a test table, insert 3 records..

/* Create Table */CREATE TABLE FunctionsDemo( 
ID INT identity(1,1), 
Name VARCHAR(50),
SSN Varchar(11),
Phone Varchar(12))

/* Insert Test Records */INSERT INTO FunctionsDemo VALUES 

I'll basically add a "OLE DB Source" to get the records from the database, then a derived column to use these expressions goodies.

The package should look like that...I'll assume that you know how to use the source and will skip its configurations.

 And here's my expressions at work, in the Derived Column Transformation.

Which I’m using the above various expression, to get the last 4 digits of the SSN, to validate if the phone number in the right format, replace a null SSN or to get the area code from the phone number, which is simple and basic but will give you the idea of how you could use these new functions.
 And here's the results

The package was created using SQL 2012..
The package can be downloaded from

Hope that helps someone...