应收收款核销记录携带单据自定义字段SQL参考原创
112人赞赏了该文章
506次浏览
编辑于2024年08月28日 19:03:25
业务场景:单据新增自定义字段并配置了携带到核销单与核销记录,历史核销单及核销记录需要携带单据自定义字段
适用场景:自定义字段在单据头
如下SQL语句仅供参考!!!更新前建议做全表备份!!!
示例以业务员为例:
--核销单携带单据上业务员
merge into t_ar_matckentry t1 using ( select t.fbillno 核销单号,a.fentryid,a.fsrcbillno 源单编号,t1.fbillformid 源单类型,a.fbusinesserid 核销单业务员,b.fsaleerid 应收单业务员,c.fsaleerid 收款单业务员,d.fsaleerid 退款单业务员,case t1.fbillformid when 'AR_receivable' then b.fsaleerid when 'AR_RECEIVEBILL' then c.fsaleerid when 'AR_REFUNDBILL' then d.fsaleerid else a.fbusinesserid end 单据业务员 from t_ar_matck t left join t_ar_matckentry a on a.fid=t.fid left join t_bas_billtype t1 on a.fsourcetype=t1.fbilltypeid left join t_ar_receivable b on t1.fbillformid='AR_receivable' and a.fsrcbillid=b.fid --应收单 left join t_ar_receivebill c on t1.fbillformid='AR_RECEIVEBILL' and a.fsrcbillid=c.fid --收款单 left join t_ar_refundbill d on t1.fbillformid='AR_REFUNDBILL' and a.fsrcbillid=d.fid --收款退款单 where a.fbusinesserid<>case t1.fbillformid when 'AR_receivable' then b.fsaleerid when 'AR_RECEIVEBILL' then c.fsaleerid when 'AR_REFUNDBILL' then d.fsaleerid else a.fbusinesserid end ) t2 on(t1.fentryid=t2.fentryid) when matched then update set t1.fbusinesserid=t2.单据业务员;
--核销记录携带单据上业务员
merge into t_ar_recmacthlogentry t1 using ( select a.fid 核销序号,a.fentryid,a.fsrcbillno 单据编号,a.fsourcefromid 源单类型,a.fbusinesserid 业务员,b.fsaleerid 应收单业务员,c.fsaleerid 收款单业务员,d.fsaleerid 退款单业务员,e.fbusinesserid 核销单业务员,case a.fsourcefromid when 'AR_receivable' then b.fsaleerid when 'AR_RECEIVEBILL' then c.fsaleerid when 'AR_REFUNDBILL' then d.fsaleerid when 'AR_Match' then e.fbusinesserid else a.fbusinesserid end 单据业务员 from t_ar_recmacthlogentry a --应收核销记录 left join t_ar_receivable b on a.fsourcefromid='AR_receivable' and a.fsrcbillid=b.fid --应收单 left join t_ar_receivebill c on a.fsourcefromid='AR_RECEIVEBILL' and a.fsrcbillid=c.fid --收款单 left join t_ar_refundbill d on a.fsourcefromid='AR_REFUNDBILL' and a.fsrcbillid=d.fid --收款退款单 left join t_ar_matckentry e on a.fsourcefromid='AR_Match' and a.fsrcbillid=e.fid and a.fsrcrowid=e.fentryid --应收核销单 where a.fbusinesserid<>case a.fsourcefromid when 'AR_receivable' then b.fsaleerid when 'AR_RECEIVEBILL' then c.fsaleerid when 'AR_REFUNDBILL' then d.fsaleerid when 'AR_Match' then e.fbusinesserid else a.fbusinesserid end ) t2 on (t1.fentryid=t2.fentryid) when matched then update set t1.fbusinesserid=t2.单据业务员;
赞 112
112人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读