Pandaaaa906

Untitled

Feb 28th, 2022 (edited)
1,631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.82 KB | None | 0 0
  1. SELECT
  2. case when inv_pos_sum.cWhCode in ('01') then replace(inv_pos_sum.cInvCode, 'M-', '') else inv_pos_sum.cInvCode end cInvCode,
  3. inv_pos_sum.cBatch,
  4. inv_pos_sum.cWhCode,
  5. inv_pos_sum.cPosCode,
  6. inv_pos_sum.cFree1,
  7. inv_pos_sum.iQuantity,
  8. -- rd01_summary.cInvCode,
  9. -- rd01_summary.cFree1,
  10. rd01_summary.cSCloser,
  11. so_d.iSOsID,
  12. so_d.cSCloser
  13. FROM InvPositionSum inv_pos_sum
  14.  
  15. LEFT JOIN Inventory inv
  16. on inv_pos_sum.cInvCode = inv.cInvCode
  17.  
  18. LEFT JOIN (
  19. SELECT
  20. row_number() over (partition by rd01_d.cInvCode, rd01_d.cBatch ORDER BY so_d.iSOsID asc) r,
  21. rd01_d.cInvCode,
  22. rd01_d.cBatch,
  23. so_d.cFree1,
  24. so_d.cSCloser,
  25. so_d.iSOsID
  26.  
  27. FROM rdrecords01 rd01_d
  28.  
  29. LEFT JOIN SO_SODetails so_d
  30. ON rd01_d.iorderdid = so_d.iSOsID
  31.  
  32. LEFT JOIN SO_SOMain so_m
  33. ON so_d.ID = so_m.ID
  34.  
  35. -- GROUP BY rd01_d.cInvCode, rd01_d.cBatch
  36. ) rd01_summary
  37. on inv_pos_sum.cInvCode = rd01_summary.cInvCode
  38. AND inv_pos_sum.cBatch = rd01_summary.cBatch
  39. and rd01_summary.r=1   -- 之前漏了这行
  40.  
  41.  
  42. LEFT JOIN rdrecords10 rd10_d
  43. ON inv_pos_sum.cInvCode = rd10_d.cInvCode
  44. AND inv_pos_sum.cBatch = rd10_d.cBatch
  45. AND inv_pos_sum.cFree1 = rd10_d.cFree1
  46.  
  47. LEFT JOIN SO_SODetails so_d
  48. ON rd10_d.iorderdid = so_d.iSOsID
  49.  
  50.  
  51. WHERE inv_pos_sum.iQuantity > 0
  52. and inv_pos_sum.cFree1 != ''
  53. -- AND inv.cInvCCode not in (
  54. -- '01031001',
  55. -- '03031001',
  56. -- '03021005',
  57. -- '03011006',
  58. -- '01011006',
  59. -- '01021005'
  60. -- )
  61. AND inv_pos_sum.cWhCode in (
  62. '01',
  63. '03',
  64. '06',
  65. '12'
  66. )
  67. -- 剔除有关联销售订单,且规格一致,且行关闭人为空
  68. AND not (
  69.     rd01_summary.iSOsID is not null
  70.     and rd01_summary.cSCloser is null
  71.     and inv_pos_sum.cFree1 = rd01_summary.cFree1
  72. )
  73. -- 根据产成品入库单,提出有关联销售订单,且行关闭人为空的
  74. and not (
  75. so_d.iSOsID is not null
  76. and so_d.cSCloser is null
  77. )
  78.  
  79. ORDER BY inv_pos_sum.iQuantity desc
Add Comment
Please, Sign In to add comment