We help IT Professionals succeed at work.

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

2,655 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


Comment
Watch Question

Doug BishopDatabase Developer

Commented:
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

Author

Commented:
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.

Author

Commented:
I'm trying a slightly different tact based on article:
https://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
'--------------------------------------------------------------------------------------------------------
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>I'm trying a slightly different tact based on article:<<
That is the correct way to do it :)
CERTIFIED EXPERT

Commented:
Closed, 125 points refunded.
modus_operandi
Community Support Moderator
CERTIFIED EXPERT

Commented:
Closed, 125 points refunded.
modus_operandi
Community Support Moderator

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.