http://reddymsbitools.blogspot.com

Tuesday, 22 February 2011

How to load Uneven Flatfiles ?

UnStructured Flat file data
0,1,2
1,2,3,4,5,6,7
1,2,3,4,5
a,b,c,d,e,f,g



' Microsoft SQL Server Integration Services Script Component
' Write scripts using Microsoft Visual Basic 2008.
' ScriptMain is the entry point class of the script.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

_
_
Public Class ScriptMain
Inherits UserComponent


Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Row.Col1 = tokenise(Row.Column0, ",", 1)
Row.Col2 = tokenise(Row.Column0, ",", 2)
Row.Col3 = tokenise(Row.Column0, ",", 3)
Row.Col4 = tokenise(Row.Column0, ",", 4)
Row.Col5 = tokenise(Row.Column0, ",", 5)
Row.Col6 = tokenise(Row.Column0, ",", 6)
Row.Col7 = tokenise(Row.Column0, ",", 7)

End Sub
Private Function tokenise(ByVal input As String, ByVal delimiter As String, ByVal token As Integer) As String
Dim tokenarray As String()
tokenarray = input.Split(delimiter.ToCharArray)
If tokenarray.Length < token Then
Return ""
Else
Return (token - 1)
End If
End Function
End Class

No comments:

Post a Comment