Go Back   CORTEX Forums > Local Happenings > CORTEX Blogs > BI Monkey
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

The Script Transformation part 2 ? as a Source

This is a discussion on The Script Transformation part 2 ? as a Source within the BI Monkey forums, part of the CORTEX Blogs category; Fig 1: The Script Transformation In this post I will be covering using the Script Transformation as a Source . The sample package can be found here for 2005 and ...


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 6th September 2009, 09:09 PM   #1
Guru
 
Join Date: Jun 2009
Posts: 135
James Beresford is on a distinguished road
Thumbs up The Script Transformation part 2 ? as a Source

Fig 1: The Script Transformation


In this post I will be covering using the Script Transformation as a Source. The sample package can be found here for 2005 and guidelines on use are here.

How can you use the Script Component as a source?

One thing I skipped over in my previous post was that when you drag a Script Component on to the Data Flow surface, you are prompted as to whether you want to use it as a source, destination or transformation (the default). If you opt to use it as a source, it configures itself differently, so it has no inputs and a single output by default, to which you need to add columns, as below:

Fig 2: Adding Output Columns to the Script Transformation


To populate rows, in the code you add a row to the Output Buffer using the AddRow method. You then assign values to the columns that you specified – the columns will be properties of the Output Buffer which will appear on Intellisense. Each time you hit the AddRow method you close off the previous row for that buffer. Below is a simple example generating some rows of data using a simple code loop. Each time the loop starts a iteration, I call the AddRow method for the Output0Buffer (the default one created when you set up the component). Then I set the values for the RowId and RowName columns using them as properties of the Output0Buffer. In this case, the code speaks a thousand words:
Public Overrides Sub CreateNewOutputRows()

‘ Define a loop counter
Dim i As Int32

‘ Loop the counter between 1 and 10 with a For / next loop
For i = 1 To 10

‘ Call the AddRow method on the Output Buffer variable
Output0Buffer.AddRow()

‘ Set the RowId property of the Output Buffer to the Loop counter
Output0Buffer.RowId = i

‘ Use a Case statement to decide the RowName property value
Select Case i

Case 1, 2, 3
Output0Buffer.RowName = “Under 3″

Case 4, 5, 6, 7
Output0Buffer.RowName = “Between 4 and 7″

Case 8, 9, 10
Output0Buffer.RowName = “Over 8″

End Select

Next i ‘ Do the next iteration of the loop

End Sub

So it’s not really that complicated to build a simple source. For those looking for some more advanced capabilities i’ve also included a couple of extra examples in the sample package. In the first (2b) I output rows to multiple outputs, sending a different set of rows to each output. In the second I read data from a table in the AdventureWorks database within the script source and modify it a little before sending it out to the data flow. It’s important to note you need to use a ADO .NET (Datareader) connections to access a database through a script’s own connection manager collection. Adding an ADO.NET connection manager for use in the script is simple – as shown below:

Fig 3: Adding a Connection Manager to a Script Component


Note the Connection Manager is from the Connection Managers for the package, not internalised to the Script Component itself.

Where would you use the Script Component as a source?

I’ve used it a couple of times to generate rows (such as default values for dimension tables), and the other common use would be when you need to access a data source that cannot be reached by standard SSIS components, but can be coded up to return a set of rows out of VB.Net / C#, for example a web service, or a particularly awkwardly formatted text file.

MSDN Documentation for the Script Transformation can be found here for 2008 and here for 2005.

If you are still struggling, try these additional resources:
If you need specific help or advice, or have suggestions on the post, please leave a comment and I will do my best to help you.



Get More from the original blog...
James Beresford is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Script Transformation part 1 ? a simple Transformation James Beresford BI Monkey 0 1st September 2009 02:01 PM
Getting File Information with the Script Task James Beresford BI Monkey 0 26th August 2009 06:37 PM
The Slowly Changing Dimension Transformation, part 2 ? Type 2 Dimensions James Beresford BI Monkey 0 11th August 2009 11:58 AM
The Slowly Changing Dimension Transformation, part 1 James Beresford BI Monkey 0 28th July 2009 10:37 PM
Open Source admin Reporting Tips and Techniques 5 7th February 2009 12:12 PM


All times are GMT +11. The time now is 11:07 PM.

© The Business Intelligence Group

Search Engine Optimization by vBSEO