在SSIS中将VARCHAR转换为DATE

时间:2019-11-15 14:38:27

标签: sql-server tsql ssis

我在SSIS包中有一个数据流任务,该任务将数据从平面文件加载到表中。

在源数据中,有一个日期列,格式为DD / MM / YYYY,我正在尝试将其转换为YYYY-MM-DD并将其转换为日期。我的“派生列”任务中的表达式为:

(DT_DATE)(SUBSTRING(SaleDate,7,4) + "-" + SUBSTRING(SaleDate,4,2) + "-" + SUBSTRING(SaleDate,1,2))

但是此任务失败,并出现以下错误:

Error: 0xC0049064 at Load into Staging, Derived Column [2]: An error occurred while attempting to perform a type cast.
Error: 0xC0209029 at Load into Staging, Derived Column [2]: 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[SaleDate2]" 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.
Error: 0xC0047022 at Load into Staging, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Derived Column" (2) failed with error code 0xC0209029 while processing input "Derived Column Input" (3). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.
Error: 0xC02020C4 at Load into Staging, Flat File Source [12]: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.
Error: 0xC0047038 at Load into Staging, SSIS.Pipeline: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on Flat File Source returned error code 0xC02020C4.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.

这是我的表情编辑器:

expression editor

我知道这可能是一个很普遍的问题,但是在寻找答案时,我发现没有任何帮助。

我错过了明显的事情吗?

1 个答案:

答案 0 :(得分:1)

在将数据查看器附加到派生的列任务之后,我最终自己发现了问题,我意识到date列在源文件中带有双引号。我调整了SUBSTRING参数以进行补偿,并且导入现在可以正常进行。