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;
1条答案
按热度按时间7z5jn7bk1#
这就是你的逻辑:
顺便说一句,最好使用日期文字
DATE '9999-12-31'
而不是CAST('9999-12-31' AS DATE)
.你想解决的最后一个商业问题是什么?看起来像是在缓慢变化的维度中识别坏数据。