Using variables in SSIS – Simple example

Using variables in SSIS – Simple example

Working with variables in SSIS: A simple demonstration

Before building the ETL package we need create a sales history table:

Insert sample data as below.

ETL requirement: Design a ETL package to extract data from sales history to a staging table. Data needs to be loaded for the given financial year only. This financial year value will be changing.

Solution:

Create a new package and name it as “Sales_Stage_Load”.

  1. Add connection managers to source and destination
  2. Create a variable “Year” and assign a default value “2006”.
  3. Add an “Execute SQL Task” to clean up the staging table. Map the parameter value with the variable as data needs to be cleaned for the given financial year only.
  4. Add a “Data Flow” task.
  5. Inside the data flow, add OLEDB source and OLEDB destination.
  6. OLEDB Source: Select data from source for the given financial year. Since the value is dynamic the parameter needs to be mapped with the variable “Year”.
  7. OLEDB Destination: Load data into staging table.

Implementation:

Create a package and add connection managers to source and destination.

Create a variable “Year” as below.

Add “Execute SQL Task” to the control flow and apply the properties as below.

Connection should point to the destination.

SQL statement is to delete data from stage table for the given year value.

Now MAP parameters in Parameter Mapping tab as below.

Now add a dataflow task and now the control flow looks like below.

Inside the dataflow create an OLEDB source and map it with the connection “Source”.

Data access should be “SQL Command”.

Map the parameter to the user defined parameter “Year” as below.

Map the columns as below.

Add destination and map it with the connection manager “Destination”.

Now the dataflow looks like below.

Now add “Data viewers” which can be helpful in validating the output.

Finally Dataflow looks like as below.

Execute the package:

Execution 1:

Initially the variable “Year” value is: 2006.

Now execute the package and see the output as below.

We can see there’s only one row available for the year 2006.

Execution 2:

Change the variable value to 2010.

Now execute the package and see the output as below.

We can see there are three rows available for the year 2010.

Note: This is just a sample to showcase how variables are being used in SSIS packages.

 

Posted in MSBI, SSIS | Tagged , , , , , | Leave a comment

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz