如何在SSIS中将DT_STR转换为DateTimeoffset [英] How to convert DT_STR to DateTimeoffset in SSIS
问题描述
我已将需要导出数据的平面文件分隔到OLEDB Destination Table。
I have delimited flat file where in need to export data to OLEDB Destination Table.
输入:SCanDatetime:DT_STR
Input : SCanDatetime : DT_STR
低于格式
当我在T-SQL中查询这种日期格式我遵循这个格式:
when I query this kind of Date format in T-SQL I follow this format :
Switchoffset ( 子串 ( ScanDateTime
<跨度>的' - 05:00' 强> 跨度> <跨度> <强>)强> 跨度>&NBSP;&NBSP;
, 1 ,
的 22 强> 跨度> <跨度>的)+ 强> 跨度> <跨度>的 ':'强> 跨度> <跨度> <强> + 子字符串 ( ScanDateTime
, 23
获取DATETIMEOFFSET -5小时
Switchoffset (Substring(ScanDateTime
, 1,
22)+':'+Substring(ScanDateTime
, 23,24),'-05:
'-05:00')
to get DATETIMEOFFSET -5hrs
我使用Derived列将其命名为Out date
I have used Derived column to name it as Out date
然后我使用脚本并将SCANDATETIME列转换为DATETIMEOFFSET格式并将该outdate映射到Destination表中。
and after that I used script and taken SCANDATETIME column to convert into DATETIMEOFFSET format and mapped that outdate into Destination table .
组件中的脚本:
public 覆盖 void
Input0_ProcessInputRow ( Input0Buffer
行 )
{
如果 (! 行 。 ScanDateTime_IsNull
&& ! 字符串 跨度> <跨度> IsNullOrEmpty 跨度> <跨度>(跨度> <跨度>行跨度> <跨度> 跨度> <跨度> ScanDateTime 跨度> <跨度>)) {
日期时间 dtDate
= 日期时间 跨度> <跨度>解析跨度> <跨度>(跨度> <跨度>行跨度> <跨度> 跨度> <跨度> ScanDateTime 跨度> <跨度>);
DateTimeOffset offDate
= 新 DateTimeOffset ( dtDate ,
;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;
TimeZoneInfo 。 FindSystemTimeZoneById ( "中央标准时间" )。 GetUtcOffset ( dtDate ));
行 。 outDate
= offDate ;
} 其他 {
;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; 行 。 outDate_IsNull
= 真实 ;
}
}
public override void
Input0_ProcessInputRow(Input0Buffer
Row)
{
if (!Row.ScanDateTime_IsNull
&& !String.IsNullOrEmpty(Row.ScanDateTime)){
DateTime dtDate
= DateTime.Parse(Row.ScanDateTime);
DateTimeOffset offDate
= new DateTimeOffset(dtDate,
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time").GetUtcOffset(dtDate));
Row.outDate
= offDate;
}else{
Row.outDate_IsNull
= True;
}
}
但是当我运行Package时,它在Derived Column中失败了
But when I run the Package it is failing in the Derived Column itself
错误:
[Derived列[2]]错误:尝试执行类型转换时发生错误。
[Derived Column [2]] Error: An error occurred while attempting to perform a type cast.
[派生列[2]]错误:SSIS错误代码DTS_E_INDUCEDTRANSFORMFAILUREONERROR。 "衍生列"是指"衍生列"。失败,因为错误代码0xC0049064发生,并且错误行处置"Derived Column.Outputs [Derived Column Output] .Columns [outdate]"
指定出错时失败。指定组件的指定对象发生错误。 在此之前可能会发布错误消息,其中包含有关失败的更多信息。
[Derived Column [2]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Derived Column" failed because error code 0xC0049064 occurred, and the error row disposition on "Derived Column.Outputs[Derived Column Output].Columns[outdate]" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
推荐答案
嗨 mohan1111,
Hi mohan1111,
根据您的问题和我的测试,如果列中有表达式
(DT_DBTIMESTAMPOFFSET,5)[扫描日期时间] 的派生列将失败; 扫描日期时间具有空值。
According to your issue and my test, the derived column with your expression (DT_DBTIMESTAMPOFFSET,5)[Scan Date Time] will fail if the column Scan Date Time has null value.
请在派生列中尝试以下表达式:
[扫描日期时间] =="" ? NULL(DT_DBTIMESTAMPOFFSET,7):( DT_DBTIMESTAMPOFFSET,7)[扫描日期时间]
最好的问候,
Mona Lv
这篇关于如何在SSIS中将DT_STR转换为DateTimeoffset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!