select * from (select distinct d.vbillcode 请购单号,
e.name 采购组织,
f.user_name 请购制单人,
d.dmakedate 请购制单时间,
d.vdef1 请购总金额,
h.vbillcode 采购合同号,
g.vbdef15 合同Code云采,
a.vbillcode 采购订单号,
a.vmemo 采购订单备注,
(case
when g.vbdef15 is not null then
'经过云采招标/寻源'
when a.vmemo = '来自云采系统的订单' then
'经过云采招标/寻源'
else
'无'
end) as sm
from po_order a
left join po_order_b b
on a.pk_order = b.pk_order
and nvl(b.dr, 0) = 0
left join po_praybill_b c
on c.pk_praybill_b = b.cpraybillbid
and nvl(c.dr, 0) = 0
left join po_praybill d
on d.pk_praybill = c.pk_praybill
and nvl(d.dr, 0) = 0
left join org_purchaseorg e
on e.pk_purchaseorg = a.pk_org
and nvl(e.dr, 0) = 0
left join sm_user f
on f.cuserid = d.creator
and nvl(f.dr, 0) = 0
left join ct_pu_b g
on g.csrcbid = c.pk_praybill_b
and nvl(g.dr, 0) = 0
left join ct_pu h
on h.pk_ct_pu = g.pk_ct_pu
and nvl(h.dr, 0) = 0
where d.vbillcode is not null
${if(len(制单开始日期) > 0 &&len(制单结束日期) > 0,
" and d.dmakedate BETWEEN '" + 制单开始日期 + "' AND '" + 制单结束日期 + "'",
"") }
${if(len(请购单号) > 0, "AND d.vbillcode ='" + 请购单号 + "'", "") }
${if(len(采购组织) > 0, "AND e.name ='" + 采购组织 + "'", "") }
${if(len(制单人) > 0, "AND f.user_name ='" + 制单人 + "'", "") }
${if(len(采购合同号) > 0,
"AND h.vbillcode ='" + 采购合同号 + "'",
"") } ${if(len(采购订单号) > 0,
"AND a.vbillcode ='" + 采购订单号 + "'",
"") }
order by d.vbillcode)
where 1=1 ${if(len(说明) > 0, "AND sm in('" + 说明 + "')", "") }
这种情况才可以用sm