Sunday, 14 October 2018

EvaluateAsExpression property in SSIS

When we are creating a dynamic package we need to deal with variables. These variables are used to achieve some value based on its calculation like we need to get the file name, dynamic connection manager, FTP connection etc. These variables may have the static or dynamic value which gets evaluated based on some expression. For evaluating the variable at runtime we must need to set “EvaluateAsExpression = True” in the variable property.
By default the value is false. If the value is false it will not evaluate the dynamic value.
See how to set this property.
Select the variable and press F4 key we will get the variable property window. Here we need to set EvaluateAsExpression to true.
  

Let’s see the example.
In the package, I am creating two variable as Current_Date_Time_F, Current_Date_Time_T
Current_Date_Time_F
 I am setting EvaluateAsExpression property as false.
  
 
Although I am assigning the expression it will not evaluate. I am setting the default values is ‘10/14/2018 12:55 PM’ whenever we execute this package we will get this value.
When we are setting EvaluateAsExpression to false the fx sign diapered from the variable.
  
     

Current_Date_Time_T
I am setting EvaluateAsExpression property as True.
   
                       
Whenever we execute this package we will get the current date and time value.
When we are setting EvaluateAsExpression to true the fx sign appeared on the variable.
  
                         
Now I am taking the script task to see these values.
Double click on the script task and write the below code in main
public void Main()
              {
            // TODO: Add your code here

            MessageBox.Show("Current_Date_Time_F   :   "+Dts.Variables["User::Current_Date_Time_F"].Value.ToString()
                + Environment.NewLine
                + "Current_Date_Time_T   :   " + Dts.Variables["User::Current_Date_Time_T"].Value.ToString());
                     Dts.TaskResult = (int)ScriptResults.Success;
              }
Close the script window and click ok.
Now the package is ready to run.
Running my package.
   
See the system time.
   


So if we are using the expression in the variable we need to set this property to True otherwise it will not evaluate the expression. 

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts