嵌套的 case 语句 Teradata 将 timestamp(0)、timestamp(6) 转换为日期并进行比较

Nested case statements Teradata converting timestamp(0),timestamp(6) to date and compare

  I want to generate qualify_flag as '1' always when device_end_dt = '9999-12-31 23:29:59'. If it is 
 not '9999-12-31 23:29:59' then if DEVICE_END_DT + 1 day = CREATION_DATE then qualify_flag is 0 else 1. 
DEVICE_END_DT is TIMESTAMP(0), CREATION_DATE  is TIMESTAMP(6). 
CREATION_DATE column doesn't have any value which is '9999-12-31'.

以下 case 语句因日期无效而失败,似乎“9999-12-31”以某种方式出现并且 (“9999-12-31”+ 1) 不明确。

select
case When 
        Cast(DEVICE_END_DT AS DATE) <> CAST('9999-12-31' AS DATE) 
            THEN
                case when CAST((Cast(DEVICE_END_DT AS DATE) + 1) AS DATE) = Cast(CREATION_DATE AS DATE)
                        then 0
                        else 1
                end

case when   
        Cast(DEVICE_END_DT AS DATE) = CAST('9999-12-31' AS DATE) 
            THEN
                            1 
end 
end as qualify_flag
 FROM ABC;

这是你的简化逻辑:

CASE 
  WHEN Cast(DEVICE_END_DT AS DATE) = Cast(CREATION_DATE AS DATE) - 1
  THEN 0
  ELSE 1
END

顺便说一句,最好使用 日期文字 DATE '9999-12-31' 而不是 CAST('9999-12-31' AS DATE).

您要解决的最终业务问题是什么?看起来像是在 缓慢变化的维度 .

中识别不良数据