【问题标题】:Teradata Concatenate multiple string columns format as timestampTeradata 连接多个字符串列格式为时间戳
【发布时间】:2017-07-04 16:39:34
【问题描述】:

我对 Teradata 还是很陌生,所以请原谅这一点,但我有两列,一列是日期,一列是 4 位 varchar 作为时间(24 小时)

以下是我用来连接字段以使其可读的方法,但我希望将结果作为有效时间戳输出,以便我可以执行计算。

cast(SCHEDULE_DATE as date format 'yyyy-mm-dd') || ' ' || substr(START_TIME,0,3) || ':' || substr(START_TIME,2,2)

这是我从上述查询中获得的结果示例。 2017-01-25 13:30

当我像这样运行查询时

cast(cast(SCHEDULE_DATE as date format 'yyyy-mm-dd') || ' ' || substr(START_TIME,0,3) || ':' || substr(START_TIME,2,2) as Timestamp ) as TESTVALUE

我得到无效的时间戳

【问题讨论】:

    标签: sql database teradata


    【解决方案1】:
    select  '2017-02-15'    as schedule_date
           ,'2233'          as start_time
           ,to_timestamp (schedule_date || start_time,'yyyy-mm-ddhh24mi')    as ts
    ;
    

    +---------------+------------+----------------------------+
    | schedule_date | start_time | ts                         |
    +---------------+------------+----------------------------+
    | 2017-02-15    | 2233       | 2017-02-15 22:33:00.000000 |
    +---------------+------------+----------------------------+
    

    附言
    substr 参数错误。
    Teradata 使用1 作为起点。


    select  '1234'                  as start_time
           ,substr(start_time,0,3)  as original_1
           ,substr(start_time,2,2)  as original_2
           ,substr(start_time,1,2)  as correct_1
           ,substr(start_time,3,2)  as correct_2
    ;       
    

    +------------+------------+------------+-----------+-----------+
    | start_time | original_1 | original_2 | correct_1 | correct_2 |
    +------------+------------+------------+-----------+-----------+
    | 1234       | 12         | 23         | 12        | 34        |
    +------------+------------+------------+-----------+-----------+
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-27
      • 2021-10-19
      • 1970-01-01
      • 2019-07-09
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多