Imports System Imports System.Data Imports System.Math Imports System.Text Imports System.Collections.Generic Imports Microsoft.SqlServer.Dts.Pipeline Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper Imports Microsoft.SqlServer.Dts.Runtime.Wrapper 'Note: this code was originally written/posted by the SSIS forum user, jaegd. http://forums.microsoft.com/MSDN/User/Profile.aspx?UserID=133544&SiteID=1 'Credit has been given where credit is due 'Original post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=864401&SiteID=1 Public Class ScriptMain Inherits UserComponent Private inputBuffer As PipelineBuffer Private cols As Dictionary(Of String, ColumnInfo) = New Dictionary(Of String, ColumnInfo) Private currentColumnInfo As ColumnInfo = New ColumnInfo Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) 'Read in current ORG value Dim orgString As String = Row.org.ToString 'Setup control counter Dim counter As Integer = 0 'How many segments do we have? Dim maxSegments As Integer = 5 'Create two holder variables Dim startPos As Integer = 0 Dim columnLen As Integer = 0 'Loop through segments While counter < maxSegments 'Retrieve starting position for this segment If cols.TryGetValue("Seg" + (counter + 1).ToString + "Start", currentColumnInfo) Then If Not (inputBuffer.IsNull(currentColumnInfo.colIndex)) Then startPos = inputBuffer.GetInt32(currentColumnInfo.colIndex) Else Exit While End If End If 'Retrieve length for this segment If cols.TryGetValue("Seg" + (counter + 1).ToString + "Len", currentColumnInfo) Then If Not (inputBuffer.IsNull(currentColumnInfo.colIndex)) Then columnLen = inputBuffer.GetInt32(currentColumnInfo.colIndex) Else Exit While End If End If ' retrieve column metatdata by column name If cols.TryGetValue("Segment" + (counter + 1).ToString, currentColumnInfo) Then 'set contents of current column to the appropriate segment 'inputBuffer.SetString(currentColumnInfo.colIndex, orgParts(counter)) inputBuffer.SetString(currentColumnInfo.colIndex, orgString.Substring(startPos - 1, columnLen)) End If 'increment counter (infinite loop otherwise!!) counter = counter + 1 End While End Sub Public Overrides Sub ProcessInput(ByVal InputID As Integer, ByVal Buffer As Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer) ' Get the Pipeline Buffer for subsequent ordinal column access inputBuffer = Buffer MyBase.ProcessInput(InputID, Buffer) End Sub Public Overrides Sub PreExecute() BuildColumnDictionary() End Sub Private Sub BuildColumnDictionary() Dim indexes() As Integer Dim input As IDTSInput90 Dim col As IDTSInputColumn90 Dim offset As Integer = 0 input = Me.ComponentMetaData.InputCollection(0) 'presumes GetColumnIndexes order matches iterator order 'as BufferManager is not available to my knowledge in ScriptComponent indexes = Me.GetColumnIndexes(input.ID) For Each col In input.InputColumnCollection Dim columnStructure As New ColumnInfo With columnStructure .colName = col.Name .colLength = col.Length .colIndex = indexes(offset) 'Normally, BufferManager would be used, but its not exposed in Script Component .colPrecision = col.Precision .colScale = col.Scale .colType = col.DataType End With cols.Add(col.Name, columnStructure) offset += 1 Next End Sub Public Structure ColumnInfo Dim colName As String Dim colType As DataType Dim colIndex As Int32 Dim colLength As Int32 Dim colPrecision As Int32 Dim colScale As Int32 End Structure End Class