Advertisement
Pandaaaa906

20230527收款单-信用额度对比

May 29th, 2023
1,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.87 KB | None | 0 0
  1. with closebill_summary as (
  2.     -- 销售收款单,根据客户编码汇总
  3.     SELECT
  4.     SUM( CASE WHEN cVouchType = N'48' THEN - iRAmt ELSE iRAmt END ) AS iAmount,
  5.         isnull( cCusVen, '' ) AS cDwCode,
  6.     --  isnull( cDepCode, '' ) AS cDeptCode,
  7.     --  isnull( cPersonCode, '' ) AS cPerson,
  8.         0 AS bVouchZZ,
  9.         count(*) c
  10.     --  INTO #creditTmp
  11.     FROM Ap_CloseBills
  12.     INNER JOIN ap_closebill ON ap_closebills.iid= ap_closebill.iid
  13.  
  14.     WHERE
  15.         isnull( cCancelNo, '' ) NOT LIKE 'XJ%'
  16.         AND iType < 2
  17.     --  AND ap_closebills.iid= 1000038132
  18.     GROUP BY
  19.         cCusVen
  20.     --  cDepCode,
  21.     --  cPersonCode
  22.  
  23. --  ORDER BY cDwCode
  24. )
  25.  
  26. SELECT
  27. credit_sum.*,
  28. closebill_summary.*
  29. FROM SA_CreditSum credit_sum
  30.  
  31. LEFT JOIN closebill_summary
  32. ON closebill_summary.cDwCode = credit_sum.cCusCode
  33.  
  34. WHERE credit_sum.iType = 1
  35. AND coalesce(credit_sum.farsum, 0) != COALESCE(closebill_summary.iAmount, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement