Teradata 连接多个字符串列格式作为时间戳
Teradata Concatenate multiple string columns format as timestamp
我对 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
我得到无效的时间戳
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 |
+---------------+------------+----------------------------+
P.s.
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 |
+------------+------------+------------+-----------+-----------+
我对 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
我得到无效的时间戳
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 |
+---------------+------------+----------------------------+
P.s.
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 |
+------------+------------+------------+-----------+-----------+