Expression Task in SSIS 2012

 inSSIS 2012 , we can see a new task in Control flow, named Expression Task.
Expression Task created to do assignment on package variables or parameters.
you can write any expression you want there and assign it to any variable or parameter.
for example this is sample expression :
@[User::PreviousMonth]= MONTH( DATEADD( "MM", -1, GETDATE()  )  )
This will assign previous month number to the PreviousMonth variable.
If you experienced previous version of SSIS, you remember that you can do same thing with resort of expression property of variables and set EvaluateAsExpression of that property to true.
So what is difference between Expression Task and previous method?
Actually the previous method is still working and you can use it, and Expression task didn't do any new thing. But the operation of assigning an expression result to a variable was not isolated in a TASK, the Expression Tasks comes to perform this as a TASK.
this is sample of Expression Task usage:
create a package first, add Expression task from toolbox
also add a package variable of type Int32 in package scope, and name it as PreviousMonth,
then go to expression task editor, and write this expression there:
@[User::PreviousMonth]= MONTH( DATEADD( "MM", -1, GETDATE()  )  )
then add a breakpoint to PostExecute event of expression Task,
and run the package, now when package pause at breakpoint you can see the PreviousMonth variable value in the watch window

Comments

Popular posts from this blog

SharePoint 2007 - Simple Task Dashboard

MERGE transformation in SSIS