SSIS Derived Column Expression

一世执手 提交于 2019-12-13 14:51:23

问题


Reading from a flat file that has a column containing the year and month in the following format --> "201212".

I need to insert this into a DATETIME2 column but first I must parse it with "/" and add a "01" as the day. Such that 201212 would become 2012/12/01

My expression in my Derived Column Transformation looks like this:

(DT_DBTIMESTAMP2,0)((DT_WSTR,4)SUBSTRING(RptMthDTM,1,4) + "/" + (DT_WSTR,2)SUBSTRING(RptMthDTM,5,2) + "/" + "01")

This seems like it should work and SSIS accepts this(as in it can parse the expression) but when running the package it throws a completely useless error "An error occurred while attempting to perform a type cast." along with the column it had the error on.

I didn't build this package, it was pawned off on me and I was told to get it working.

Thanks in advance interwebs family.


回答1:


DT_DBTIMESTAMP2 can only be converted from a specific string format: yyyy-mm-dd hh:mm:ss[.fffffff]

You can use this expression instead:

(DT_DBTIMESTAMP2,0)((DT_WSTR,4)SUBSTRING(RptMthDTM,1,4) + "-" + (DT_WSTR,2)SUBSTRING(RptMthDTM,5,2) + "-" + "01 00:00:00")

More details: [http://msdn.microsoft.com/en-us/library/ms141036.aspx][1]



来源:https://stackoverflow.com/questions/13752478/ssis-derived-column-expression

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!