Advertisement
Pandaaaa906

Untitled

May 8th, 2023
1,256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.42 KB | None | 0 0
  1.  
  2. SELECT
  3. case when so_d.iQuantity = so_d.iFHQuantity and so_d.cSCloser is null then '不正常'
  4. when so_d.iQuantity = so_d.iFHQuantity and so_d.cSCloser ='asuser' then '正常'
  5. when so_d.cSCloser != 'asuser' and so_d.cSCloser is not null then '取消'
  6. end status,
  7. case when COALESCE(so_d.foutquantity,0) = COALESCE(rd32_summary.iQuantity, 0) then '正常'
  8. when COALESCE(so_d.foutquantity,0) != COALESCE(rd32_summary.iQuantity, 0) then '不正常'
  9. end status_2,
  10. so_m.dDate,
  11. so_m.dverifysystime,
  12. so_d.cSCloser,
  13. so_d.AutoID,
  14. so_m.cSOCode,
  15. so_d.iSOsID,
  16. so_d.cInvCode,
  17. so_d.cFree1,
  18. so_d.iQuantity,
  19. so_d.iFHQuantity,
  20. so_d.foutquantity,
  21. so_d.foutnum,
  22. disp_summary.iQuantity disp_qty,
  23. rd32_summary.latest_date latest_date,
  24. rd32_summary.latest_veri_time latest_veri_date,
  25. rd32_summary.c c,
  26. rd32_summary.iQuantity sum_iQuantity,
  27. rd32_summary.iNum sum_iNum,
  28. so_d.iKPQuantity,
  29. so_d.fVeriDispQty,
  30. row_number() over(partition by case when so_d.iQuantity = so_d.iFHQuantity and so_d.cSCloser is null then '不正常'
  31. when so_d.iQuantity = so_d.iFHQuantity and so_d.cSCloser ='asuser' then '正常'
  32. end ORDER BY so_d.iSOsID desc) r
  33. --
  34. -- update so_d
  35. -- SET iFHQuantity = disp_summary.iQuantity
  36. -- SET foutquantity = rd32_summary.iQuantity,
  37. -- foutnum = rd32_summary.iNum
  38.  
  39. FROM [dbo].[SO_SODetails] so_d
  40.  
  41. LEFT JOIN SO_SOMain so_m
  42. ON so_d.ID = so_m.ID
  43.  
  44. LEFT JOIN (
  45. SELECT
  46. disp_d.iSOsID,
  47. sum(disp_d.iQuantity) iQuantity
  48.  
  49. FROM DispatchLists disp_d
  50.  
  51. LEFT JOIN DispatchList disp_m
  52. ON disp_d.DLID = disp_m.DLID
  53.  
  54. GROUP BY disp_d.iSOsID
  55. ) disp_summary
  56. ON disp_summary.iSOsID = so_d.iSOsID
  57.  
  58. LEFT JOIN (
  59. SELECT
  60. COALESCE(iorderdid, isodid) isodid,
  61. max(rd32_m.dDate) latest_date,
  62. max(rd32_m.dnverifytime) latest_veri_time,
  63. count(*) c,
  64. sum(iQuantity) iQuantity,
  65. sum(iNum) iNum
  66. FROM rdrecords32 rd32_d
  67.  
  68. LEFT JOIN rdrecord32 rd32_m
  69. ON rd32_m.ID = rd32_d.ID
  70.  
  71. GROUP BY  COALESCE(iorderdid, isodid)
  72. ) rd32_summary
  73. ON rd32_summary.isodid = so_d.iSOsID
  74.  
  75. WHERE 1=1
  76. -- AND rd32_summary.latest_date < '2023-03-06'
  77. -- AND so_d.iFHQuantity > 0
  78. -- AND so_d.iQuantity = so_d.iFHQuantity
  79. AND so_d.cSCloser is null
  80. AND so_d.iQuantity = COALESCE(rd32_summary.iQuantity, 0)  -- 已完全出库
  81. -- AND COALESCE(so_d.iFHQuantity,0) != COALESCE(disp_summary.iQuantity, 0)  -- 发货数量不一致
  82. -- AND COALESCE(so_d.foutquantity,0) != COALESCE(rd32_summary.iQuantity, 0)  -- 出库数量不一致
  83.  
  84.  
  85. ORDER BY rd32_summary.latest_veri_time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement