Advertisement
Pandaaaa906

20230511销售订单审核-信用额度 - 发货单部分

Jan 24th, 2024 (edited)
1,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.69 KB | None | 0 0
  1. select
  2. top 5  -- 加了限制n条
  3. cvouchtype,cdlcode as ccode,ddate,min(a.dgatheringdate) as dgatheringdate,
  4. sum(case when isnull(iquantity,0)+isnull(tbquantity,0)<>0 then isnull(iUnitPrice,0) * (isnull(iquantity,0)+isnull(tbquantity,0)-isnull(isettlequantity,0)-isnull(fretqtywkp,0))
  5. else (isnull(isum,0)-(isnull(fretsum,0)+isnull(isettlenum,0)))
  6. end+(isnull(isettlenum,0)-isnull(iexchsum,0))
  7. ) as fmoney,
  8. sum(isnull(isum,0)-(case when isnull(isum,0)=0 then 0 else cast(isnull(isettlenum,0) as decimal(26,9)) end)) uninvoice_money,
  9. sum((case when isnull(isum,0)=0 then 0 else cast(isnull(isettlenum,0) as decimal(26,9)) end)-isnull(iexchsum,0)) unpaid_money
  10.  
  11. from (dispatchlist a with (nolock)
  12. inner join dispatchlists b with (nolock) on (a.dlid=b.dlid))
  13.  
  14. left join customer with(nolock) on a.ccuscode=customer.ccuscode
  15.  
  16. where isnull(bcashsale,0) = 0
  17. and (a.bFirst=1 or (a.bFirst=0 and a.dDate>=(select cvalue from accinformation where csysid=N'SA' and cName=N'dStartDate'))) and a.cvouchtype<>N'00' and a.bcredit=1 and a.breturnflag=0
  18. and ccuscreditcompany = '11072'   -- 传入客户编码进行筛选
  19. and isnull(isum,0) <> 0
  20. and a.dlid <> 0
  21. and isnull(b.bsettleall,0) = 0
  22. and isnull(dcreditstart,N'') <> N''
  23. and isnull(cverifier,'') <> N''
  24. AND dgatheringdate < dateadd(day, -30, getdate())  -- 加了限制日期,可以配置,默认30
  25. group by cvouchtype,cdlcode,ddate,dgatheringdate
  26. having sum(isnull(isum,0)) > 0
  27. and (
  28.     sum(isnull(isum,0)-(case when isnull(isum,0)=0 then 0 else cast(isnull(isettlenum,0) as decimal(26,9)) end))>0 -- 还有未结算金额,发票?
  29.     or sum((case when isnull(isum,0)=0 then 0 else cast(isnull(isettlenum,0) as decimal(26,9)) end)-isnull(iexchsum,0))>0
  30. );
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement