Objective:: Creating Forecast Ssis - 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Objective: Generate an Excel spreadsheet that can be used to manually

enter a sales forecast by city and state. The city and state information will
be extracted from the AdventureWorksDW database and output to an Excel
spreadsheet.

Step 1: Create a new Integration Services project

Select Integration Services Project, and give the name to the project
SalesForecastInput

And renanage the package as CreateSalesForecastInput.dtsx

Step 2: The designer will now display an empty Control Flow. Click anywhere in the
Control Flow designer to bring up the package properties window.

The package properties window contains many properties that can be set for the package.
The following is an example:

Creating Forecast SSIS Page | 1


We collapse the property groups and left expanded few important ones are discuss here:

ProtectionLevel

IsolationLevel

TransactionOption

And set the values as follows

ProtectionLevel = DontSaveSensitive

IsolationLevel = Serializable

TransactionOption = Supported

The ProtectionLevel provides for various options for encrypting the package and/or
portions of the package. We point this one out because the default value of
EncryptSensitiveWithUserKey will often cause problems. An example of sensitive
information is a database connection string that contains a password in it. The
Creating Forecast SSIS Page | 2
default setting will encrypt this information using the user key of the person who
created the package. When another user executes the package it will fail
because that user's key will not be able to decrypt the connection string. A
good way around this is to change the ProtectionLevel to
DontSaveSensitive, meaning you aren't going to put sensitive information in
the package so there's no need to worry about encryption.

The IsolationLevel property is setting the Transaction Isolation Level. Note that the
default value is Serializable which may not be what you really need. Serializable is
the level where read locks are held until a transaction commits or rolls back
which provides that no data read can be updated. In addition range locks are
held so that no data can be inserted such that rerunning any query in the transaction
would return the rows added which weren't there at the beginning of the
transaction. Surely there are times when this transaction isolation level is warranted
but certainly not always. The Serializable level generally results in additional locking
and decreased concurrency so you should consider whether you really need this and
choose one of the other levels such as ReadCommitted.

The TransactionOption allows you to choose how the package behaves with respect
to database transactions. The default value of Supported is probably a good one. If
a package is executed within an existing transaction (i.e. called from another
package) it will enlist or join the transaction which certainly makes sense as a
default. The other options are Required and NotSupported. Required means that
the package will always execute within a transaction, either joining the transaction of
the caller or creating its own transaction. NotSupported means the package does
not join an existing transaction or create its own.

Step 3: Let us create the connection Managers. A Connection Manager allows you to
connect with a Data Source or Data Destination

In this section we will add two data sources to our package - one to access the
AdventureWorksDW database and another to access our Excel spreadsheet.

You can see the Connection Area at the bottom or Designer package

To add the connection manager simply right click inside the Connection Managers area then
choose New OLEDB Connection from the popup menu,
and create the connection as follows

Creating Forecast SSIS Page | 3


And it will create the connection as follows

Creating Forecast SSIS Page | 4


To add a connection manager for our Excel spreadsheet, right click inside the Connection
Managers area then choose New Connection from the popup menu, then select EXCEL from
the Add SSIS Connection Manager dialog. The Excel Connection Manager dialog will be
displayed; enter a file name as shown below:

Creating Forecast SSIS Page | 5


And connections will get added as follows

Rename the connections as follows

Step 4: Let us create the Control Flow, which contains the various tasks that the package
will perform.

On LHS, you will see the various Control Flow tasks as follows

There are quite a few built-in tasks available. For our current package we only need a Data
Flow task. Drag and drop the Data Flow Task from the Toolbox onto the Control Flow
designer. After doing so the Control Flow designer should look like this:

Creating Forecast SSIS Page | 6


Right click inside the Data Flow Task rectangle then select Rename from the popup menu.
Enter Create Sales Forecast Input Spreadsheet as the new name for the task, and it will
look as follows

Step 5: Click on the Data Flow tab in the designer and you should see the empty Data
Flow designer as shown below:

Creating Forecast SSIS Page | 7


The Toolbox will now display the tasks that are available in the Data Flow as shown below:

As you can see there are quite a few built-in tasks available.
For our current package we want to
retrieve some data from the AdventureWorksDW database and output it to an Excel
spreadsheet. To do this we need an OLE DB Source and an Excel Destination.
In addition we need to add a column to the Data Flow; this column will be the
numeric column in the spreadsheet where the user enters the forecast amount.

For these Drag and drop an OLE DB Source, Derived Column, and Excel Destination from
the Toolbox onto the Data Flow designer. After doing so the Data Flow designer should look
like this:

Creating Forecast SSIS Page | 8


The red icons inside of the tasks are an indicator that there is some configuration required.
Right click on the OLE DB Source then select Edit from the popup menu. This will open the
OLE DB Source Editor on the Connection Manager page. Fill in the dialog as shown below,
and click on OK button:

Creating Forecast SSIS Page | 9


SELECT dbo.DimGeography.GeographyKey,
dbo.DimGeography.SalesTerritoryKey, dbo.DimGeography.City,
dbo.DimGeography.StateProvinceName AS State,
dbo.DimGeography.PostalCode,
dbo.DimSalesTerritory.SalesTerritoryCountry
FROM dbo.DimGeography INNER JOIN
dbo.DimSalesTerritory ON dbo.DimGeography.SalesTerritoryKey
= dbo.DimSalesTerritory.SalesTerritoryKey
WHERE (dbo.DimSalesTerritory.SalesTerritoryCountry = N'United States')
ORDER BY State, dbo.DimGeography.City
You will now see a green and a red line dangling from the OLE DB Source task on the Data
Flow designer. The green line is the normal data flow; the red line is the error flow.

Creating Forecast SSIS P a g e | 10


Step 6: Drag the green line and connect it to the Derived Column task as shown below:

Notice that the red icon is now gone from the OLE DB Source task and it is now properly
configured.
Step 6: Derived Column
The Derived Column task allows us to add a column to the Data Flow. Right click on it,
select Edit, then fill in the Derived Column transformation Editor as shown below:

Creating Forecast SSIS P a g e | 11


Step 7: Click on the Derived Column task and drag the green arrow to connect to the Excel
Destination task.

Right click the Excel Destination task and select Edit from the popup menu. The Excel
Destination Editor dialog will be displayed. Click the New button next to the Name of the
Excel Sheet to display the Create Table dialog as shown below:

Creating Forecast SSIS P a g e | 12


The Create Table dialog allows us to create a new table in the Excel spreadsheet. The
columns and their types are determined by the data flow. We configured an OLE DB Source
task that executes a query and a Derived Column task that added the Forecast column to
the data flow.

Step 10: Now click on Control Flow. Right Click on the package and select Execute Package

While the package is running you will see each task turn green if it completes successfully or
red if it fails. Here is the Control Flow after the package has run successfully:

Here is the Data Flow after the package has run successfully:

Creating Forecast SSIS P a g e | 13


After the package completes click Debug on the top level menu then select Stop Debugging.

We can open the Excel spreadsheet that the package created and see the following (only a
portion of the spreadsheet is shown):

The above spreadsheet shows the columns from our query plus the Forecast column which
we added with the Derived Column task.

Creating Forecast SSIS P a g e | 14

You might also like