?
Solved

DTS: Using ActiveX Script replace 0 value with NULL in a datetime format field.

Posted on 2007-10-08
8
Medium Priority
?
2,592 Views
Last Modified: 2013-11-30
via DTS
Source = .csv     Field = datetime

Possible values in source file = yyyyMMdd (20071008) OR 00000000
Due to the 00000000 value a normal "Date Time String transformation" fails. As such I would like to use an active X script to replace the 00000000 value with a NULL value leaving the yyyyMMdd value if available. I am unsure of the syntax in an ActiveX script. I have been trying something like the following without success.
Any help would be appreciated.

Function Main()
If DTSDestination("REF_DT") = ("000000000") Then
DTSSource("Col014") = IsNull Else
FormatDateTime( DTSDestination("REF_DT") , yyyyMMdd ) = FormatDateTime( DTSSource("Col014") , yyyyMMdd )
End If
End Function


0
Comment
Question by:pwanveer
7 Comments
 
LVL 15

Expert Comment

by:dbbishop
ID: 20035565
You have your source and destination mixed up:

If DTSSource("Col014") = ("000000000") Then
    DTSDestination("REF_DT") = NULL
Else
    DTSDestination("REF_DT") = FormatDateTime( DTSSource("Col014") , yyyyMMdd )
End If
0
 

Author Comment

by:pwanveer
ID: 20035610
dbbishop, the function still fails. DTS doesnt provide much more info than that unfortunately. Is the else syntax correct for copying the text value into the datetime format for a SQL field?

Else
    DTSDestination("REF_DT") = FormatDateTime( DTSSource("Col014") , yyyyMMdd )

Thx for the quick response.

0
 

Author Comment

by:pwanveer
ID: 20036115
I'm trying a slightly different tact based on article:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_21898627.html?sfQueryTermInfo=1+datetim+dt+format+name

I'm getting the correct results (Nulls for 0's and source values where the value is > 0) However I need to pass the end result as a datetime format to the SQL table.

Current:
'--------------------------------------------------------------------------------------------------------
Function Main()
     DTSDestination("REF_DT") = GetDate(DTSSource("Col014"))
     Main = DTSTransformStat_OK
End Function
'--------------------------------------------------------------------------------------------------------
Function GetDate (Byval Dat)

Dat = DTSSource("Col014")

If (Dat) > 0 Then
      GetDate = DTSSource("Col014")
Else
   GetDate = Null
End If

End Function
'--------------------------------------------------------------------------------------------------------

I've tried without sucess:

'--------------------------------------------------------------------------------------------------------
Function Main()
     DTSDestination("REF_DT") = GetDate(DTSSource("Col014"))
     Main = DTSTransformStat_OK
End Function
'--------------------------------------------------------------------------------------------------------
Function GetDate (Byval Dat)

Dat = DTSSource("Col014")

If (Dat) > 0 Then
      GetDate = FormatDateTime(DTSSource("Col014"), yyyyMMdd)
Else
   GetDate = Null
End If

End Function
'--------------------------------------------------------------------------------------------------------
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
pwanveer earned 0 total points
ID: 20036502
Got it. The following works:
'--------------------------------------------------------------------------------------------------------
Function Main()
     DTSDestination("REF_DT") = GetDate(DTSSource("Col014"))
     Main = DTSTransformStat_OK
End Function
'--------------------------------------------------------------------------------------------------------
Function GetDate (Byval Dat)

Dat = DTSSource("Col014")
yyyy = Left (DTSSource("Col014"), 4)
mm  = Mid(DTSSource("Col014"), 5, 2)
dd   = Right(DTSSource("Col014"), 2)

If (Dat) > 0 Then
      GetDate = FormatDatetime(mm&"/"&dd&"/"&yyyy)
Else
   GetDate = Null
End If

End Function
'--------------------------------------------------------------------------------------------------------
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 20061905
>>I'm trying a slightly different tact based on article:<<
That is the correct way to do it :)
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20063056
Closed, 125 points refunded.
modus_operandi
Community Support Moderator
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20063057
Closed, 125 points refunded.
modus_operandi
Community Support Moderator
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question