【问题标题】:How to convert NUMBER DataType to DATE DataType in ssis如何在 ssis 中将 NUMBER 数据类型转换为 DATE 数据类型
【发布时间】:2018-09-10 05:32:34
【问题描述】:

您好,我有 csv 文件数据,例如:- (ActiveDate= 20180105) 所以我想将此列保存到我的数据库中。在我的数据库列数据类型是 datetime

当使用数据转换作为 DT_Date 我得到这个错误:-

转换返回状态值 2 和状态文本“值 由于可能丢失数据,无法转换。

那么我如何将这个 ActiveDate 数据从我的 excel 导入到我的数据库中作为 datetime

你能帮帮我吗?

【问题讨论】:

  • 您尝试过@Justin 的建议吗?您当前遇到的错误是什么?
  • 是的,我收到了这个错误:- [Derived Column [36]] Error: An error occurred while attempting to perform a type cast. [Derived Column [48]] 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[DERIVED_ADMIT_DATE]" 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.
  • Derived Column 中执行CAST 之前,您是否使用Data Conversion 将您的输入Number 转换为String
  • @Abhishek :- 是的,我已经做到了
  • 你的实现一定有问题,你可能遗漏了什么——因为描述的方法工作得很好。

标签: ssis ssis-2012


【解决方案1】:

您必须首先将您的列YYYYMMDD 转换为Data Conversion 元素中的字符串,如下所示:

  Input Column   Output Column   Data Type                      Length 
  IntDate       StringDate      Unicode string [DT_WSTR]        50  

然后您可以在Derived Column 元素中使用此公式将新字符串列转换为实际日期:

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

对于日期列中为空的数据使用此公式,此公式将在当前日期更改为空:

isnull(StringDate)? GETDATE() : (DT_DATE)(SUBSTRING(StringDate,1,4) + "-" + SUBSTRING(StringDate,5,2) + "-" + SUBSTRING(StringDate,7,2))

结果:

IntDate     StringDate  DateDate
20170809    20170809    2017-08-09 00:00:00.0000000

【讨论】:

  • 嗨贾斯汀..我是 SSIS 的新手。使用数据转换为 Unicode 字符串后能否告诉我。如何在 ssis 的派生列中使用公式??
  • 我怎样才能在派生列中仅实现日期(例如:- 2017/08/09)这种格式。??我不需要时间
  • 1.对于 Google 中的派生列示例搜索,您只需粘贴代码并将 StringDate 更改为您的列。 2. 如果您写入数据库,则插入的日期类型无关紧要。
  • 嘿,我已经完成了派生列.. 但仍然出现此错误:- [Derived Column [48]] 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[DERIVED_ADMIT_DATE]" 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.
  • 我编辑了我的答案,如果您在日期列中得到空值,请使用第二个公式。此公式将在当前日期更改为 null
猜你喜欢
  • 2016-03-10
  • 2015-07-06
  • 2013-07-06
  • 2016-09-27
  • 1970-01-01
  • 2014-01-19
  • 1970-01-01
  • 1970-01-01
  • 2017-01-01
相关资源
最近更新 更多