Advertisement
Pandaaaa906

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

Jan 24th, 2024
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.61 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 = %s  and isnull(isum,0) <> 0
  19. and a.dlid <> 0
  20. and isnull(b.bsettleall,0) = 0
  21. and isnull(dcreditstart,N'') <> N''
  22. and isnull(cverifier,'') <> N''
  23. AND dgatheringdate < getdate()  -- 加了限制日期
  24. group by cvouchtype,cdlcode,ddate,dgatheringdate
  25. having sum(isnull(isum,0)) > 0
  26. and (
  27.     sum(isnull(isum,0)-(case when isnull(isum,0)=0 then 0 else cast(isnull(isettlenum,0) as decimal(26,9)) end))>0 -- 还有未结算金额,发票?
  28.     or sum((case when isnull(isum,0)=0 then 0 else cast(isnull(isettlenum,0) as decimal(26,9)) end)-isnull(iexchsum,0))>0
  29. );
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement