Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 ActiveX transformation Error

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-09-20 : 04:39:31
Hi i was give this code to work with as a transformation in a DTS package but am getting a Error "miss match" on formatdate

for this line
DTSDestination("orderDate") = formatDate(DTSSource("Col002"))

I tried the BOL it said use CDate but that does not work either. Am new to the ActiveX...i normally use the copy column

The reason i want to use this is that my date text is in a string in the source file and i'd like to display it as datetinme in the table my orderdate datatype is DateTime.



'**********************************************************************
' Visual Basic Transformation Script
'************************************************************************

' Copy each source column to the destination column
Function Main()

Main = DTSTransformStat_OK
DTSDestination("SN") = Trim(DTSSource("Col003"))
DTSDestination("orderNumber") = Trim(DTSSource("Col001"))
DTSDestination("orderDate") = formatDate(DTSSource("Col002"))
DTSDestination("reference") = Trim(DTSSource("Col004"))
DTSDestination("country") = "EN"

End Function

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-09-20 : 05:36:12
I created this function to over come it as there was no function to work wit.



' Use this function to get better control and so you can reuse the code for other datetime columns
Function formatDate(ByVal Value)

' First convert to a date friendly format (yyyy-mm-dd)
'Value = Left(Value, 4) + "-" + Mid(Value, 5, 2) + "-" + Mid(Value, 7, 2) US format

Value = Left(Value,2) +"/" +Mid(Value,3,2) + "/"+ Mid(Value,5,4)

If IsDate(Value) Then ' Is it a valid date?
GetDate = CDate(Value)
Else
GetDate = Null 'If needed replace with some other appropriate value for invalid dates
End If

End Function
Go to Top of Page
   

- Advertisement -