Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 将vb转换从dts转换为SSI时输出空值_Sql_Sql Server_Vb.net_Vbscript_Ssis - Fatal编程技术网

Sql 将vb转换从dts转换为SSI时输出空值

Sql 将vb转换从dts转换为SSI时输出空值,sql,sql-server,vb.net,vbscript,ssis,Sql,Sql Server,Vb.net,Vbscript,Ssis,我正在努力将一些使用ActiveX VBScript转换的旧dts包转换为SSIS包。输入为YYYYMMDD格式的8个字符的字符串。如果可能的话,转换是将其转换为日期。如果不是,则该值应为NULL 这是dts代码 TheYear = Mid(DTSSource("SHIP_DATE"),1,4) TheMonth = Mid(DTSSource("SHIP_DATE"),5,2) TheDay = Mid(DTSSource("SHIP_DATE"),7,2) TheDate = TheMont

我正在努力将一些使用ActiveX VBScript转换的旧dts包转换为SSIS包。输入为YYYYMMDD格式的8个字符的字符串。如果可能的话,转换是将其转换为日期。如果不是,则该值应为NULL

这是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
以下是我为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
我尝试将OutShipDate格式化为日期和数据库日期。对于无效的日期输入字符串(如00000000),根据OutShipDate的数据类型,我在数据库列中获得1899-12-30或0001-01-01。如果在VBScript中未将Row.OutShipDate设置为任何值,则SSIS执行将完全失败


我可以从VBScript转换中输出空值吗?

如果不转换为日期

Row.OutShipDate = CDate(TheDate)
DB列是否设置为允许NULL

更新

If IsDate(TheDate) Then
    Row.OutShipDate = CDate(TheDate)
Else
    Row.OutShipDate = DBNull.value
End If
另一个更新

If IsDate(TheDate) Then
    Row.OutShipDate = DateTime.Parse(TheDate("MM/dd/yyyy"))
Else
    Row.OutShipDate = DirectCast(Nothing, System.Nullable(Of DateTime))
End If
这就是对我有用的

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

我找到了答案,现在我知道它是什么了,这似乎是愚蠢的容易

基本上,如果我想返回空日期,代码应该是

Row.OutShipDate_IsNull = True

谢谢你的建议。是,DB destination列允许空值。CDateTheDate导致包执行失败。好的,您能举几个例子说明作为字符串的日期是什么吗。如果可能的话,好的和坏的。2014年4月9日的有效日期是20140409,大多数无效日期是00000000,我想为这些日期返回Null。。。返回可为null的对象必须有一个值。在System.Nullable`1.get_值处。我想我会放弃并将其设置为Nothing,然后执行一个单独的sql update语句,将“0001-01-01”的所有内容设置为NULL。不过我很感谢你的帮助。@jessieloo我刚遇到一个关于可取消日期的部分,是David T Macket寄来的。。。它在列表的下方,所以请继续滚动。