select * from ( select m.CheckDate,LEFT ( CONVERT(varchar(100), m.CheckDate, 112),6) as period ,ve.VendCustCode, ve.VendCustName, --case when ar.AreaName4 is not null then ar.AreaName4 else sh.AreaName4 end AreaName4 AR.AreaName4,AR.AreaName2,AR.fullName ,m.BillNo,'汇款' BookAccountTypes,PB.Amount*(-1) as Amount,cu.CurrencyName from FIRP_Pre_RPVoucherMaster m --left join vwFI_BookAccountTypes bt on bt.BillNo =m.BillNo left join vwFI_BookAccountTypes bt on bt.BillNo =m.BillNo left join Bas_InterCompany ve on ve.VendCustID =m.ObjectValue left join #Cust_OperationArea ar on ar.VendCustID =ve.VendCustID left join Bas_Currency cu on cu.CurrencyID =m.CurrencyID LEFT JOIN FIRP_Pre_BookAccountDetail PB ON PB.BillNo = m.BillNo where BillTypeID ='Fin_PreRecVoucher' AND M.BillStatus ='4' and m.ObjectType ='1' AND PB.BookAccountID = 'YM000001' AND PB.Amount<>0 UNION ALL SELECT A.CheckDate,LEFT ( CONVERT(varchar(100), A.CheckDate, 112),6) as period ,B.VendCustCode, B.VendCustName,AR.AreaName4,AR.AreaName2,AR.fullName,A.BillNo,'' BookAccountTypes, case when ToBookAccountID = 'YM000001' then -C.TransferAmount else C.TransferAmount end as Amount -- -C.TransferAmount AS Amount ,'人民币' AS CurrencyName FROM FIRP_Pre_BATransfer A LEFT JOIN vwSD_CustomerManerage B ON B.VendCustID=A.ObjectValue left join Bas_InterCompany ve on ve.VendCustID =A.ObjectValue left join #Cust_OperationArea ar on ar.VendCustID =ve.VendCustID LEFT JOIN FIRP_Pre_BATransferDetail C ON C.BillNo=A.BillNo WHERE A.BillStatus=4 AND (C.ToBookAccountID='YM000001' OR C.SourceBookAccountID='YM000001')---该条件用于取默认货款账户 ) as FIRP where VendCustCode = 'LY189' ==================================================== |