SSIS 字符串转时间格式注意事项

        花了两天时间,终于把字符串  转成Integration Services 数据类型的时间格式。

       微软官方说明中,当数据进入包中的数据流时,提取这些数据的源会将数据转换为 Integration Services 数据类型。为数值数据分配数值数据类型,为字符串数据分配字符数据类型,为日期分配日期数据类型。 其他数据,如 GUID 和二进制大型对象块 (BLOB),也要分配相应的 Integration Services 数据类型。 如果数据的数据类型无法转换为 Integration Services 数据类型,则会发生错误。

     对于时间格式的转换,需要特别注意,需要转换的字符串格式。 在微软官网说明中有一篇文章,对这一转换了做了详细的说明。

    http://technet.microsoft.com/zh-cn/library/ms345165%28v=sql.90%29.aspx

   http://technet.microsoft.com/zh-cn/library/ms141036%28v=SQL.90%29.aspx


   字符串转 时间类型,字符串需要对应的格式。 如 yyyy.mm.dd hh:mm:ss  是无法转换为时间格式的,需要对字符串做预处理。

 Converting Between Strings and Date/Time Data Types

The following table lists the results of casting or converting between date/time data types and strings:

  • When you use the cast operator or the Data Conversion transformation, the date or time type data type will be converted to the corresponding string format. For example, the DT_DBTIME data type will be converted to a string that has the format, "hh:mm:ss".

  • When you want to convert from a string to a date or time data type, the string must use the string format that corresponds to the appropriate date or time data type. For example, to successfully convert some date strings to the DT_DBDATE data type, these date strings must be in the format, "yyyy-mm-dd".

    Data type

    String format

    DT_DBDATE

    yyyy-mm-dd

    DT_FILETIME

    yyyy-mm-dd hh:mm:ss:fff

    DT_DBTIME

    hh:mm:ss

    DT_DBTIME2

    hh:mm:ss[.fffffff]

    DT_DBTIMESTAMP

    yyyy-mm-dd hh:mm:ss[.fff]

    DT_DBTIMESTAMP2

    yyyy-mm-dd hh:mm:ss[.fffffff]

    DT_DBTIMESTAMPOFFSET

    yyyy-mm-dd hh:mm:ss[.fffffff] [{+|-} hh:mm]

In the format for DT_FILETIME and DT_DBTIMESTAMP fff is a value between 0 and 999 that represents fractional seconds.

In the date format for DT_DBTIMESTAMP2, DT_DBTIME2, and DT_DBTIMESTAMPOFFSET, fffffff is a value between 0 and 9999999 that represents fractional seconds.

The date format for DT_DBTIMESTAMPOFFSET also includes a time zone element. There is a space between the time element and the time zone element.


猜你喜欢

转载自blog.csdn.net/feifly329/article/details/23335059
今日推荐