在DB2 sql过程中 - 选择查询结果 - 如果condition - substring

时间:2012-05-07 15:53:20

标签: sql db2 substring procedure

我正在写一个db2程序。 我的选择查询结果有我必须比较的日期时间。

日期格式20120507时间格式111111

我打算连接两者并比较为整数。这是正确的比较方式吗?

但如果它小于10,则该值将类似于71111 ..我计划在这些情况下在时间之前追加0并进行连续比较。

我能否在单一声明中这样做。

select dbdate,  if   LENGTH(trim(dbtime))=7   then  '0'||dbtime into newtime   from tablename

1 个答案:

答案 0 :(得分:0)

尝试使用

中的TIMESTAMP标量函数
 select  TIMESTAMP(dbdate, dbtime)

这为您提供了可用于比较操作的db / 2时间戳。在进行比较之前,最好将所有日期/时间值转换为时间戳,然后根据需要truncateround