WISE OWL EXERCISES
SSIS INTEGRATION SERVICES EXERCISES
- Data flow tasks (4)
- Basic data transforms (1)
- Data conversion transforms (2)
- Conditional split transforms (5)
- Lookup transforms (4)
- Looping over files (3)
- Looping over rows (2)
- Merge joins (1)
- Previous versions (18)
- Script tasks (1)
- Variables in script (1)
- Script components (2)
- Accessing file attributes (2)
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!
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:
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:
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:
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 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.