简体   繁体   English

从DTS到SSIS转换VB转换时输出空值

[英]outputting null values when converting vb transformation from dts to ssis

I am struggling with converting some old dts packages that use ActiveX VBScript transformations to SSIS packages. 我正在努力将一些使用ActiveX VBScript转换的旧dts包转换为SSIS包。 The input is an 8 character string in YYYYMMDD format. 输入为YYYYMMDD格式的8字符串。 The transformation is converting it to a date if possible. 如果可能,转换会将其转换为日期。 If not, the value should be NULL. 如果不是,则该值应为NULL。

Here is the dts code 这是DTS代码

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 这是我进行SSIS转换所需要的

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. 我尝试将OutShipDate格式化为日期和数据库日期。 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. 对于无效的日期输入字符串,例如“ 00000000”,我在数据库列中得到1899-12-30或0001-01-01,具体取决于OutShipDate的数据类型。 If I don't set Row.OutShipDate to anything in the VBScript, the SSIS execution fails completely. 如果我未在VBScript中将Row.OutShipDate设置为任何值,则SSIS执行将完全失败。

Can I output a null value from the VBScript transformation? 我可以从VBScript转换中输出一个空值吗?

Should you not convert to date.... 如果您不转换为日期...。

Row.OutShipDate = CDate(TheDate)

Is the DB column set to allow NULL? DB列是否设置为允许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

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 基本上,如果我想返回NULL日期,则代码应为

Row.OutShipDate_IsNull = True

This link helped ultimately 该链接最终帮助了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM