zhangjinrui(提问者)select ta.单据日期, ta.凭证编号,ta.期初余额,ta.供应商编码,ta.供应商名称,ta.票据类型,ta.单据号,ta.摘要,ta.币种,ta.应收应付标志,ta.应付款摘要,ta.修改日期
from (select ap.dVouchDate as 单据日期,ap.cPZNum as 凭证编号,ap.iAmount as 期初余额,ap.cDwCode as 供应商编码,v.cVenName as 供应商名称 ,ap.cVouchType as 票据类型,ap.cVouchID as 单据号,case bStartFlag when 1 then \'期初余额\' end as 摘要/*数据属性*/,ap.cexch_name as 币种,ap.cFlag as 应收应付标志,ap.cDigest as 应付款摘要,ap.cOperator as 录入人,ap.cCheckMan as 审核人 ,ap.dmoddate as 修改日期
from Ap_Vouch ap,Vendor v
where bStartFlag=1/*期初余额表,数据正确*/ and ap.cdwcode=v.cVenCode
union all
select pb.dpbvdate as 开票日期,pbs.cPZNum as 凭证号,sum(isum)as 本期应付 /*本期应付*/ ,pb.cVenCode as 供应商编码,v.cVenName as 供应商名称,case bFirst when 0 then \'采购发票\' end as 单据类型 ,cPBVCode as 单据号 ,pb.cPBVMemo as 摘要,pb.cexch_name as币种 ,pb.cdefine1 ,pb.cdefine1,pb.cPBVVerifier as 审核人,cPBVMaker as 制单人,pb.dGatheringDate as 到期日
from PurBillVouch pb,PurBillVouchs pbs,Vendor v
where pb.pbvid=pbs.PBVID and pb.cVenCode=v.cvencode and pb.cVenCode=v.cVenCode
group by cPBVCode,pb.cPBVMemo ,pbs.cPZNum ,pb.cVenCode ,pb.cPBVVerifier ,cPBVMaker ,pb.cPBVCode ,pb.dGatheringDate ,pbs.PBVID,dpbvdate,bFirst,v.cVenName,pb.cDefine1,pb.cexch_name/*发票*/
union all
select ap.dvouchdate as 票据日期,ap.cDefine9 as 凭证编号,aps.iApplyAmt as 本期付款申请金额 ,ap.cdwcode as 供应商编码,v.cVenName as 供应商名称,case cVouchType when \'AP40\' then \'付款申请单\'end as 单据类型, ap.cVouchID as 单据号,ap.cdigest as 摘要,ap.cexch_name as 币种,cdefine1,cdefine1,ss.cSSName as 结算方式,ap.cCheckMan as 检查人,ap.dCloseDate as 关闭日期
from AP_ApplyPayVouch ap,AP_ApplyPayVouchs aps,Vendor v,SettleStyle ss
where ap.PID=aps.pid and ap.cDwCode=v.cVenCode and ap.cSSCode=ss.cSSCode/*付款申请表*/)ta
group by ta.供应商编码,ta.供应商名称,ta.单据日期, ta.凭证编号,ta.期初余额,ta.票据类型,ta.单据号,ta.摘要,ta.币种,ta.应收应付标志,ta.应付款摘要,ta.修改日期