Oracle SQL - 连接2个日期

时间:2015-02-02 17:03:32

标签: sql oracle

我有以下代码。 它有2个日期:

1

(case 
    when not trunc(iv.dated) is null then trunc(iv.dated) else trunc(iv1.dated) 
end) date_stock_received

2

trunc(dh.actshpdate) SHIP_DATE

有没有办法加入日期,以便它们显示在一列中?

select unique li.catnr, li.av_part_no, 
(select sum(pl.qty_onhand) from part_loc pl where li.av_part_no = pl.part_no) qty_onhand,
(case 
    when not trunc(iv.dated) is null then trunc(iv.dated) else trunc(iv1.dated) 
end) date_stock_received,
(case 
    when not sum(iv.quantity) is null then sum(iv.quantity) else sum(iv1.quantity) 
end) qty_received,
dp.delqty, od.ord_extordnr, trunc(dh.actshpdate) SHIP_DATE
from leos_item li
LEFT JOIN scm_packtyp sp
    ON li.packtyp = sp.packtyp
LEFT JOIN invtran_view_oes iv
    ON li.av_part_no = iv.part_no 
    and (iv.transaction = 'NREC' and iv.location_no = '        RETURNS    W')
LEFT JOIN invtran_view_oes iv1
    on li.av_part_no = iv1.part_no
    and (iv1.transaction = 'CORR+' and iv1.remark like 'STOCK FROM SP PALLET%')
LEFT JOIN oes_delsegview od
    ON od.catnr = li.catnr
    and od.prodtyp = li.prodtyp
    and od.packtyp = li.packtyp
LEFT JOIN oes_dpos dp
    ON od.ordnr = dp.ordnr
    and od.posnr = dp.posnr
    and od.segnr = dp.segnr
LEFT JOIN oes_dhead dh
    on dp.dheadnr = dh.dheadnr
    and dh.shpfromloc = 'W'
where li.cunr = '816900'
and substr(li.catnr,1,5) in ('RGMCD','RGJCD')
and li.item_type = 'FP'
and li.catnr = 'RGJCD221'
group by li.catnr, li.av_part_no, iv.dated, iv.quantity, iv1.dated, iv1.quantity, dp.delqty, 
dp.ordnr, dp.posnr, dp.segnr, od.ord_extordnr, dh.actshpdate
order by li.av_part_no

目前的结果是......

enter image description here ......我希望看到的是......

enter image description here 这可能吗?

1 个答案:

答案 0 :(得分:0)

合并功能可能就是你想要的。

select trunc(coalesce(iv.dated, iv1.dated, dh.actshpdate)) theDateYouMightWant