SQLDTS.comSQLIS.comSQLIS Wiki
The Script Component(As A Transform)
By Allan Mitchell
Version 2005
Level Intermediate
Page 1 | Page 2 | Page 3 | Page 4 | Page 5

All we need to do now is add our code.

What we need to do is loop over a row of input data extracting the multivalued attribute values one at a time. For every value found in the column we need to add another row to the Output Buffer. In our example sample of data we had 3 input rows but will be returning 18 output rows of data.

Here is the code to do that.

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        '
        'The Row parameter to this method is a collection of our input attributes 
        'We can work with this using .Net and add to the Output our data.
        'See the following

        'Read our comma delimited rows into an array
        Dim arr() As String = Row.Readings.Split(","c)

        Dim iReadingCount As Integer = 1

        'we loop around on the same row so long as there are
        'delimited values to be extracted

        For i As Integer = 0 To arr.Length - 1

            With Output0Buffer
                'add a row to the output buffer
                .AddRow()
                'Set the values of each of our output buffer columns
                .SiteID = Row.siteID
                .ReadingID = iReadingCount
                .DateOfReading = System.DateTime.Now
                .Reading = CType(arr(i), Integer)

                'Increase the reading count by 1
                iReadingCount += 1

            End With
        Next
    End Sub

This component is really powerful and will have a huge amount of uses.

Page 1 | Page 2 | Page 3 | Page 4 | Page 5
Page Last Updated: 02 Aug 2004 (307)