如何在teradata中处理日期coulmn中的空值

时间:2015-07-27 11:08:08

标签: teradata

这是我的sql,我想处理date coulmn的空值。

SQL:

insert into r_intraday_netrev
      ( report_time, snapshot_time, prodtype, qty, yestasp,
        m2_cumpct, m2_predictedunits, m2_rev, m3_cumpct, m3_predictedunits, m3_rev)
select current_time as report_time,
        **max(ss_sb1.snapshot_time),**------want to handle nulls for this date coulmn 
        'ZTOTAL',
        null,
        null,
        null,
        null,
        sum(round( ( (ss_sb1.qty / ss_p2.cumpct) * ss_sb2.asp ) , 0)),
        null,
        null,
        sum(round( ( (ss_sb1.qty / ss_p3.cumpct) * ss_sb2.asp) , 0)) 
from DW_CORE.ss_topline_a_v  ss_sb1
left outer join DW_CORE.ss_topline_rsst_b_v ss_sb2 ON ss_sb1.prodtype = ss_sb2.prodtype 
left outer join DW_CORE.ss_predict_p2_v  ss_p2 ON  (ss_sb1.prodtype = ss_p2.prodtype AND td_day_of_week(ss_sb1.snapshot_time) = ss_p2.dayofweek 
AND substr(to_char(ss_sb1.snapshot_time, 'HH24MI' ),1,3)||'0' =  ss_p2.timeofday)
left outer join DW_CORE.ss_predict_p3_v  ss_p3 ON  (ss_sb1.prodtype = ss_p3.prodtype AND (snapshot_time - interval '364' day) = ss_p3.lastyear_date 
AND substr(to_char(snapshot_time, 'HH24MI' ),1,3)||'0' =  ss_p3.lastyear_time) ;
你可以请任何人帮助我......

2 个答案:

答案 0 :(得分:1)

您可以使用以下内容检查日期中的NULLS:

COALESCE((CAST(datecolumn as varchar2(10))),'')<>'' '

答案 1 :(得分:0)

假设您要默认为2019的YEND:

select coalesce(date_column, to_date('2019-12-31')) from your_table;