一、定義查詢參數
二、寫查詢執行SQL
select distinct ts_payapply.billno as billno,
ts_payapply.wish_paydate wish_paydate,
(case when ts_payapply.vbillstatus=0 then '審批未通過'
when ts_payapply.vbillstatus=1 then '審批通過'
when ts_payapply.vbillstatus=2 then '審批進行中'
when ts_payapply.vbillstatus=3 then '提交狀態'
when ts_payapply.vbillstatus=8 then '自由態'
when ts_payapply.vbillstatus=5 then '提交狀態'
when ts_payapply.vbillstatus=11 then '單據支付中'
when ts_payapply.vbillstatus=12 then '付款成功'
end ) vbillstatus,
ts_payapply_b.fph as fph,
cubasdoc.custname custname,
djzb.djbh as djbh,
ts_payapply_b.ret_datetime as ret_datetime,
ts_payapply_b.ret_message as ret_message
from ts_payapply
inner join ts_payapply_b
on ts_payapply.pk_payapply = ts_payapply_b.pk_payapply and nvl(ts_payapply.dr,0)=0
left join (select * from djfb where nvl(dr,0)=0 and djdl='fk' and dwbm=#LoginCorp#) djfb
on ts_payapply_b.pk_payapply_b = djfb.ddhh and
nvl(ts_payapply_b.dr, 0) = 0 and nvl(djfb.dr, 0) = 0
and ts_payapply_b.pk_payapply = djfb.ddlx
left join (select * from djzb where nvl(dr,0)=0 and djdl='fk' and dwbm=#LoginCorp#) djzb
on (djfb.djdl = 'fk' and nvl(djzb.dr, 0) = 0 and djfb.vouchid = djzb.vouchid)
inner join cubasdoc on ts_payapply_b.pk_cubasdoc = cubasdoc.pk_cubasdoc
where ( ts_payapply_b.pk_cubasdoc in (#supplier#) or
( ' '= ( select a from ( select #supplier# a , rownum from dual ) where a =' ' )) )
and (ts_payapply.billno =#billno# or #billno# is null)
and ( ts_payapply.wish_paydate >=#wish_paydate# or #wish_paydate# is null )
order by wish_paydate desc
注:1、查詢參數多選,SQL手工設計使用的查詢參數是替代參數,即把查詢參數直接替換到sql語句裏面,所以 #supplier# is null 在多選情況下就會變成 '12312312','234wereq32' is null ,造成sql語法錯誤,操作符選擇=時,則不會存在語法問題 2、order by 字段是在查詢視圖返回結果集以後再執行的,不能寫 order by ts_payapply.wish_paydate desc