Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with closebill_summary as (
- -- 销售收款单,根据客户编码汇总
- SELECT
- SUM( CASE WHEN cVouchType = N'48' THEN - iRAmt ELSE iRAmt END ) AS iAmount,
- isnull( cCusVen, '' ) AS cDwCode,
- -- isnull( cDepCode, '' ) AS cDeptCode,
- -- isnull( cPersonCode, '' ) AS cPerson,
- 0 AS bVouchZZ,
- count(*) c
- -- INTO #creditTmp
- FROM Ap_CloseBills
- INNER JOIN ap_closebill ON ap_closebills.iid= ap_closebill.iid
- WHERE
- isnull( cCancelNo, '' ) NOT LIKE 'XJ%'
- AND iType < 2
- -- AND ap_closebills.iid= 1000038132
- GROUP BY
- cCusVen
- -- cDepCode,
- -- cPersonCode
- -- ORDER BY cDwCode
- )
- SELECT
- credit_sum.*,
- closebill_summary.*
- FROM SA_CreditSum credit_sum
- LEFT JOIN closebill_summary
- ON closebill_summary.cDwCode = credit_sum.cCusCode
- WHERE credit_sum.iType = 1
- AND coalesce(credit_sum.farsum, 0) != COALESCE(closebill_summary.iAmount, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement