Domanda

I am struggling with converting some old dts packages that use ActiveX VBScript transformations to SSIS packages. The input is an 8 character string in YYYYMMDD format. The transformation is converting it to a date if possible. If not, the value should be NULL.

Here is the dts code

TheYear = Mid(DTSSource("SHIP_DATE"),1,4)
TheMonth = Mid(DTSSource("SHIP_DATE"),5,2)
TheDay = Mid(DTSSource("SHIP_DATE"),7,2)
TheDate = TheMonth &"/"&TheDay&"/"&TheYear

If IsDate(TheDate) Then
    DTSDestination("SHIP_DATE") = TheDate
End If

Here is what I have for the SSIS transformation

Dim TheYear As String
Dim TheMonth As String
Dim TheDay As String
Dim TheDate As String

If Row.SHIPDATE.Length >= 8 Then
    TheYear = Row.SHIPDATE.Substring(0, 4)
    TheMonth = Row.SHIPDATE.Substring(4, 2)
    TheDay = Row.SHIPDATE.Substring(6, 2)
    TheDate = TheMonth & "/" & TheDay & "/" & TheYear
    If IsDate(TheDate) Then
        Row.OutShipDate = TheDate
    Else
        Row.OutShipDate = Nothing
    End If
Else
    Row.OutShipDate = Nothing
End If

I have tried formatting OutShipDate as both date and database date. For an invalid date input string such as "00000000", I get either 1899-12-30 or 0001-01-01 in my database column depending on the dataype of OutShipDate. If I don't set Row.OutShipDate to anything in the VBScript, the SSIS execution fails completely.

Can I output a null value from the VBScript transformation?

È stato utile?

Soluzione 2

I found the answer and now that I know what it is, it seems stupidly easy.

Basically, if I want to return a NULL date, the code should be

Row.OutShipDate_IsNull = True

This link helped ultimately

Altri suggerimenti

Should you not convert to date....

Row.OutShipDate = CDate(TheDate)

Is the DB column set to allow NULL?

UPDATE

If IsDate(TheDate) Then
    Row.OutShipDate = CDate(TheDate)
Else
    Row.OutShipDate = DBNull.value
End If

Another Update...

If IsDate(TheDate) Then
    Row.OutShipDate = DateTime.Parse(TheDate("MM/dd/yyyy"))
Else
    Row.OutShipDate = DirectCast(Nothing, System.Nullable(Of DateTime))
End If

This is what worked for me....

Dim TheDate As String = "36/29/2014"
'Dim TheDate As String = "4/9/2014"    

    Dim DDB As Date

    If IsDate(TheDate) Then
        DDB = CDate(TheDate)
    Else
        DDB = Nothing
    End If
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top