如何解决派生列中的类型转换错误 [英] How to solve Type cast error in Derived column

查看:134
本文介绍了如何解决派生列中的类型转换错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有分隔文本文件,我正在加载到数据库表中



在文本文件中


1。 COL1:预测交货日期:DT_STR格式


2.COL2  :ScanDateTime:DT_STR格式



目的地表:


1。 COL1:预计交货日期:DATE  (数据类型)


2.COL2  :ScanDateTime:DATETIME,我需要加载以下格式的数据


Switchoffset
子串 ScanDateTime 
1
22 + ' :' + 子串
ScanDateTime
23 24 ), ' - 05:00'


我尝试使用Derived列将此数据加载到目标表中:


我为 Col 1 :(DT_DBDATE)LEFT([Predicted]提供了此表达式交货日期],10)


col2  :( DT_DATE)(SUBSTRING([ScanDateTime  ],1,4)+" - " + SUBSTRING([ScanDateTime  ],5,2)
+" - " + SUBSTRING([ ScanDateTime  ],7,2), ' - 05:00'


但两者都给出错误:



[派生列[2]]错误:发生错误尝试执行类型转换时。




[派生列[2]]错误:SSIS错误代码DTS_E_INDUCEDTRANSFORMFAILUREONERROR。  "派生列"失败,因为发生错误代码0xC0049064,并且"派生列。输出[派生列输出] .Columns [预测]"
上的错误行处置指定错误失败。指定组件的指定对象。在此之前可能会显示错误消息,其中包含有关失败的更多信息。



对于Col1:预测交货日期我需要如何处理Null值并将数据加载到目标表中,即日期格式


对于Col2  :ScanDateTime:我如何为
Switchoffset
<编写表达式span style ="color:blue; font-family:Consolas; font-size:9.5pt">
(exp) - 5小时 为该日期时间列并加载 


解决方案

嗨  mohan1111,


根据您的问题,我们可以在派生中使用以下表达式列。


表达式:


COL1: [预测交货日期] =="" ? NULL(DT_DBDATE):( DT_DBDATE)[预测交货日期]


COL2: DATEADD(" Hh", - 5,(DT_DATE)[扫描日期时间] ])




请参阅  < a href ="https://docs.microsoft.com/en-us/sql/integration-services/expressions/dateadd-ssis-expression?view=sql-server-2017"> DATEADD(SSIS表达式)  。


我希望我的解决方案会有所帮助。


最好的问候,


Mona Lv <强>


I have Delimited text file where I'm loading into Database table

In Text file

1. COL1 : Predicted delivery date : DT_STR Format

2.COL2  : ScanDateTime : DT_STR Format

In Destination Table :

1. COL1 : Predicted delivery date : DATE  (DataType)

2.COL2  : ScanDateTime : DATETIME and I need to load data in this below format

Switchoffset (Substring(ScanDateTime , 1, 22)+':'+Substring(ScanDateTime , 23, 24),'-05:00')

I have trying to load this data into destination table using Derived column :

I gave this expression for  Col 1  : (DT_DBDATE)LEFT([Predicted Delivery Date],10)

col2  : (DT_DATE)(SUBSTRING([ScanDateTime ],1,4) + "-" + SUBSTRING([ScanDateTime ],5,2) + "-" + SUBSTRING([ScanDateTime ],7,2),'-05:00')

But both are giving error :

[Derived Column [2]] Error: An error occurred while attempting to perform a type cast.


[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[Predicted]" 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.

For Col1 : Predicted delivery date how I need to handle Null values and Load the data into Destination table which is Date Format

For Col2  : ScanDateTime : How I can write an expression for Switchoffset (exp) - 5hrs for that date time column and load  

解决方案

Hi mohan1111,

According to your issue, we could use the following expression in derived column.

Expression:

COL1: [Predicted delivery date] == "" ? NULL(DT_DBDATE) : (DT_DBDATE)[Predicted delivery date]

COL2: DATEADD("Hh",-5,(DT_DATE)[Scan Date Time])

Plese refer to DATEADD(SSIS Expression) .

I hope my solution would be helpful.

Best Regards,

Mona Lv


这篇关于如何解决派生列中的类型转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆