dbTalk Databases Forums  

Script Component Transform

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Script Component Transform in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David
 
Posts: n/a

Default Script Component Transform - 07-18-2006 , 03:52 PM






I have a flat file that in the Date fields has the data in the form 99991231.
SQL will not accept this date a) because it is out of range and b) it
appears that SSIS does not like the format but would like to see it in
9999/12/31. I am trying to create a Script Component that will modify the 4
columns in the file but I keep getting the following error when I run the
package "Object reference not set to an instance of an object."


I am going from a Flat file to a SQL 2005 table.

Here is my script from the transform:

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)
'
' Add your code here
'
' Convert Date to SQL format and change 99991231 to 2078/12/31

Dim leaving_date As String
Dim entry_date As String
Dim expiry_date As String
Dim birth_date As String

If Row.leavingdate.Trim.Length > 0 Then


If (Row.leavingdate = "99991231") Then

leaving_date = "2078/12/31"

Else


leaving_date = Row.leavingdate.Substring(0, 4) + "/" +
Row.leavingdate.Substring(4, 2) + "/" + Row.leavingdate.Substring(6, 2)

End If

Row.leavingdate = leaving_date

End If

If Row.entrydate.Trim.Length > 0 Then


If (Row.entrydate = "99991231") Then

entry_date = "2078/12/31"

Else

entry_date = Row.entrydate.Substring(0, 4) + "/" +
Row.entrydate.Substring(4, 2) + "/" + Row.entrydate.Substring(6, 2)

End If

Row.entrydate = entry_date

End If

If Row.expirydate.Trim.Length > 0 Then



If (Row.expirydate = "99991231") Then

expiry_date = "2078/12/31"

Else

expiry_date = Row.expirydate.Substring(0, 4) + "/" +
Row.expirydate.Substring(4, 2) + "/" + Row.expirydate.Substring(6, 2)

End If

Row.expirydate = expiry_date

End If

If Row.birthdate.Trim.Length > 0 Then



If (Row.birthdate = "99991231") Then

birth_date = "2078/12/31"

Else

birth_date = Row.birthdate.Substring(0, 4) + "/" +
Row.birthdate.Substring(4, 2) + "/" + Row.birthdate.Substring(6, 2)

End If

Row.birthdate = birth_date

End If

End Sub

End Class



This is my attempt at doing this so please be gentle

Thanks,
David Inman

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.