【问题标题】:Importing Excel data into SQL Server and converting to DateTime将 Excel 数据导入 SQL Server 并转换为 DateTime
【发布时间】:2017-06-05 20:53:11
【问题描述】:

伙计们,

我在 Excel 文件中有一些日期时间数据,其格式适合 SQL Server 日期时间转换 (yyyy-mm-dd hh:mm:ss:000)。不幸的是,当我尝试将数据导入 DateTime 类型的 SQL 字段时,我收到以下错误消息:

Error 0xc02020c5: Data Flow Task 1: Data conversion failed while converting column "Datetime" (27) to column "Datetime" (60).  The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data."

Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "Data Conversion 0 - 0.Outputs[Data Conversion Output].Columns[Datetime]" failed because error code 0xC020907F occurred, and the error row disposition on "Data Conversion 0 - 0.Outputs[Data Conversion Output].Columns[Datetime]" 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: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Data Conversion 0 - 0" (52) failed with error code 0xC0209029 while processing input "Data Conversion Input" (53). 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: Data Flow Task 1: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.

Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on Source - Sheet2$ 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.

知道我做错了什么吗?我特别必须从 Excel 而不是从 CSV 导入,因为源文件中有希伯来语文本,SQL Server 拒绝使用 CSV 导入中可用的任何编码来识别。

`

【问题讨论】:

  • 日期时间 (27) 和数据时间 (60) 似乎是不同的格式。尝试将 excel 列更改为与您的 sql 日期格式匹配的自定义格式日期,具体取决于您的语言设置。
  • excel列的格式目前是自定义的DateTime:yyyy-mm-dd hh:mm:ss.000。我应该把它改成什么?
  • 您可能想在 ss 和 000 之间尝试使用句点而不是冒号。如果仍然无法正常工作,可以尝试以字符串形式导入,然后在导入后使用 cast()。
  • 那是在正确的轨道上 - 完全删除了毫秒并且它起作用了!

标签: sql-server excel datetime


【解决方案1】:

最终起作用的是完全删除毫秒。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 2019-09-02
    相关资源
    最近更新 更多