Tutorial: Creating Your First SSIS Package

Who is online?  0 guests and 0 members
Home  »  Articles  »  Tutorial: Creating Your First SSIS Package

Tutorial: Creating Your First SSIS Package

change text size: A A A
Published: 12/17/2009 by  BrianKnight  - Views:  [1668]  

The learning curve of SQL Server 2005 is like going from SQL Server  2000. Maybe even worse for DTS. Any knowledge of DTS you have now can be thrown out in SQL Server 2005. When I started to create my first DTS package, it was quite a humbling experience as I clumsily navigated around the interface. This tutorial will walk you through the creation of your first simple SSIS package and guide you through some of the features.

 

Download the Sample File

 

The goal of this tutorial is to transform data inline from a flat file to another flat file without ever having to stage the data like you would typically have to do in SQL Server 2000. We’re going to take a sample file with just under 90,000 records and aggregate it, group it and sort it before inserting it into a new text file. You can also insert into a SQL Server just as easy. Traditionally in SQL Server 2000 or 7.0, you would have to insert data into a staging area, use a query to aggregate, sort and group it and then write the flat file out. This query won’t require any knowledge of how to query a SQL Server system.

 

Before you begin, download the sample text file attached to this article.

 

 

  1. Open the Business Intelligence Development Studio (Start | Programs | Microsoft SQL Server 2005). This is where you will typically create your DTS packages now. The environment as you can see is Visual Studio 2005.
  2. Select File | New | Project
  3. Under the Business Intelligence Projects Project Type, select Integration Services Project. Call the project Tutorial1 under the Name text box. Click OK. This will create a new project and your first blank package called Package.dtsx.
  4. Double-click on Package.dtsx in the right-pane (Solution Explorer) under SSIS Packages.
  5. This will open the new Package Designer. You should start in the Control Flow tab. The Control Flow tab is where you start your workflow. Each time you transform data move data, you will automatically be redirected to the Data Flow tab. We’ll cover much more about these tabs shortly.
  6. There are lots of ways of doing data connections. You can create a shared connection that works across multiple SSIS packages or you can create one that has the scope of the existing package. In our example here, let’s start simple and just do a local connection. To do this, right-click in the Connections tab below and select New Flat File Connection.
  7. You are then taken to the New Flat File Connection dialog box. By now, you should have downloaded the sample file. If you haven’t downloaded the file, please download it as part of this article. Name this connection Sample File and no description is needed but it is useful metadata if you’d like. The file name should point to C:\DTS\SampleText.txt or wherever you placed the flat file. Another area that will be different than the defaults is to change the text qualifier to double-quotes (“). Here’s my properties screen.
    1. Before clicking OK, go through the other areas of the dialog box like the Columns screen.
    2. This part is very important and don’t skip this step as the rest of the tasks will rely on this. Go to the Column Properties screen. By selecting each column, you can see what data type SSIS is using for that column in the flat file. Select the column TransactionDate then under data type select date [DT_DATE]. A really cool feature here is you can click Suggest Type to have DTS sample the data and predict what you need. When it suggests the data type, it will predict for all the columns and not just the one you have selected. Click Suggest and OK to finish the rest of the columns. One thing I have noticed is you want to make sure the Quantity column is a 4-byte integer and not a 2-byte integer.
    3. Click Preview to confirm that the settings you choose are good.
    4. After you see data on the Preview section, then you’re ready to select OK.

 

bkDTSTutorial1-1.JPG 

  1. You’ll now see the new connection at the bottom. We’ll create another one of these later to show you another method of doing this.
  2. In the far left pane, you should be able to see the Toolbox tab. Hover over Toolbox and click and drag the Data Flow Task control onto the Control Flow tab. (You can optionally pin the toolbox to your design environment by clicking the push pin.)
  3. Right click on the newly created task and select Rename. Type “Transform Flat File” as the new task name. (You can also left click on the task and modify the Name property in the Properties pane on the right). 
  4. Right-click on the Data Flow task you just renamed and select Edit. This will take you to the Data Flow tab.
  5. Once on the Data Flow tab, drag and drop the Flat File Source data flow item onto the design pane from your Toolbox in the left.
    1. You may want to optionally rename the data flow item by right-clicking the item and selecting Rename. I renamed mine to Sample File.
  6. Right-click on Sample File data flow item and select Edit. Under the Connection option in the left pane ensure that Sample File is selected for your connection. Next, go to the Columns section and uncheck most of the columns, leaving only ProductID, TransactionDate, Quantity and ActualCost.

    bkDTSTutorial1-2.JPG

 

  • Next, click and drag the Derived Column data flow item over to the design pane under the Sample File item. Again, right-click on the Derived Column item and select Rename. Rename it to Total Cost. Left-click the Sample File data item and you’ll see a red and green arrow pointing down. Left-click the green arrow and drag it onto the Total Cost item. With the two items connected, go ahead and right-click on the Total Cost item and select Edit.
  • In the Derived Column Editor, drill into the Columns tree in the right and drag the Quantity and ActualCost columns into the Expression column below as shown in the below screen shot. Make the Expression Column Quantity * ActualCost. If you receive a data type error, then you may not have followed step 7b. Change the name of the Derived column to TotalCost and the data type to Currency as shown below. After you’ve done this, click OK. What this does is create an extra column that can be seen by the destination transformation and will sum up those two columns.

    bkDTSTutorial1-3.JPG

  • Next, we need to roll up the data. Drag and drop the Aggregate data item from the Toolbox into the design pane. Again, connect the Total Cost data item to the new data item by connecting the green line as you did before in step 15. Let’s rename this data item to Group by Product.
  • Go to the Aggregate Editor by right-clicking on Group by Product and selecting Edit. Then check the ProductID, TransactionDate, Quantity and TotalCost columns. This will partially fill in the Input Column area below. You will then need to specify what type operation you’d like to do for each of the columns. We want to group on ProductID so you need to ensure that Group By is selected. For Quantity select Sum and for TotalCost select Sum. Finally select Maximum for the TransactionDate Input Column. I also changed the Output Aliases for two of the columns to give a unique name to the new data. Essentially, what I’m doing here is grouping all the data by ProductID, determining the maximum date from the TransactionDate column and summing up all the quantity and cost. Click OK to save your work in this screen. Notice:  that the TotalCost column is available to you here. So as you add derived columns, they show up in later data items.

    bkDTSTutorial1-4.JPG
  • We now want to sort the data so it makes our new flat file easy to read. To do this click and drag the Sort data item from the Toolbox and rename it to Order by ProductID. Make sure it’s connected to the Group by Product item by connecting the green arrow from the Group by Product item.
  • Go to edit this data item as we did the other items. Check ProductID and ensure that’s being order ascending. Click OK to exit.

    bkDTSTutorial1-5.JPG

  • Lastly, we need to output all this work to another flat file. Click and drag Flat File Destination (it’s not in alphabetical order) over from the Toolbox.  Ensure it’s connected to the Order by ProductID item by dragging the green arrow from that item.
  • Click edit to modify the properties of the Flat File Destination.
    1. Click New to create a new flat file connection
    2. Name this connection SummaryByProductID (see below for other info).
    3. Notice in the Preview section, you can see all the output columns from the earlier items. 
    4. Click OK
    5. bkDTSTutorial1-6.JPG

     

    1. In the Mappings section, ensure that the transformation looks fine. Click OK.

      bkDTSTutorial1-7.JPG
    2. You’re now done. To execute the package hit the F5 button or click Start under the Debug menu. You’ll then see the record counts increasing.  Here’s an example of my output.

    bkDTSTutorial1-8.JPG

     

    I hope this got you past your first SSIS package. In the next tutorial, I’ll show you how to add some basic error handling to the package so you can easily get past something like what I mentioned in the last paragraph.

     

  •  
    0
    /5
    Avg: 0/5: (0 votes)

    Comments (4)

    raguram
    raguram said:
    A very comprehensive tutorial ! Thanks brian :)
    11/30/2009
     · 
     
    by
    adrian
    adrian said:
    Looks good. Nice tutorial that works smoothly. Thanks
    12/21/2009
     · 
     
    by
    jtarnott
    jtarnott said:
    I'll have to pass this along to colleagues who have not yet got their SSIS feet wet. One thing to maybe edit: The point that says "Lastly, we need to output all this work to another flat file. Click and drag Flat File Destination (it’s not in alphabetical order) over from the Toolbox." is not completely true if you've right-clicked the toolbox and chosen "Sort items alphabetically". MS does force "Pointer" to the top of each section, but the rest of the components are indeed sorted.
    12/21/2009
     · 
     
    by
    venkat
    venkat said:
    Hi Brian, Great article. I would like to prepare for MCTS test on BI. Please let me know some preparation tips or give me any references you have. I do have the Wrox Book "Professional Microsoft SQL Server 2008 Integration Services" written by you. I felt this book is very helpful to learn SSIS. Can know which chapters are more important in order to prepare for MCTS. Would appreciate your help.
    12/22/2009
     · 
     
    by

    Most Recent Articles