SSIS Integration Services | Script components exercise | Use a script component to add a new column to a table

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

You can learn how to do this exercise if you attend one of more of the courses listed below!

Software ==> SSIS Integration Services  (46 exercises)
Version ==> SSIS 2012 and later
Topic ==> Script components  (2 exercises)
Level ==> Relatively easy
Courses ==> Fast track SSIS  /  Advanced SSIS
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Create a new package called Calculate durations, and within this create a data flow task which reads in rows from the above workbook.  Include a script component at the end:

Script component in data flow

The script component has a cross against it because you haven't configured it yet!

 

The imported data contains two columns for each series, giving the premiere date and the finale date:

List of series

It should be possible from these to work out how long each series lasted.

 

Get your script component to calculate and output a new column giving the duration of each series in days, using code similar to the following:

// take the time difference, and convert it into days

Row.DurationDays = (Row.Finale - Row.Premiere).Days;

Note that you'll need to pass in the Premiere and Finale input columns to the script component, but also add DurationDays as an integer output column.

Add a Union All transform and a data viewer to get this:

Final package

When you run the package, it should show your existing columns plus the one you've added in your scrpt component.

 

Run your package - you should see something like this:

Series durations

Series 1 was the shortest series by far.

Take a few moments to think how much easier (and better!) it would have been to use a derived column transform to solve this problem instead, then close down your package. 

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post