Advertisement
Pandaaaa906

Untitled

Feb 1st, 2023
1,824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.48 KB | None | 0 0
  1. /*
  2. SELECT
  3. *
  4. INTO db_backup.dbo.rdrecord32_20230131
  5. FROM rdrecord32
  6. ;
  7. SELECT
  8. *
  9. INTO db_backup.dbo.DispatchList_20230131
  10. FROM DispatchList
  11. ;
  12. */
  13. SELECT
  14. dept.cDepName voucher_dept_name,
  15. rd32_m.cCode,
  16. rd32_m.dDate,
  17. cus.cCusName,
  18. rd32_m.cDepCode,
  19. rd32_m.cPersonCode,
  20. cus.cCusDepart,
  21. cus.cCusPPerson,
  22. new_dept.cDepName
  23.  
  24. -- update rd32_m
  25. -- SET cDepCode = cus.cCusDepart,
  26. -- cPersonCode = cus.cCusPPerson
  27.  
  28. FROM rdrecord32 rd32_m
  29.  
  30. LEFT JOIN Department dept
  31. ON rd32_m.cDepCode = dept.cDepCode
  32.  
  33. LEFT JOIN Customer cus
  34. ON cus.cCusCode = rd32_m.cCusCode
  35.  
  36. LEFT JOIN Department new_dept
  37. ON cus.cCusDepart = new_dept.cDepCode
  38.  
  39. WHERE rd32_m.dDate >= '2023-01-01'
  40. -- AND rd32_m.bTransFlag = 0
  41. AND (
  42. dept.cDepName like '%停用%'
  43. or dept.cDepCode = '0102'
  44. )
  45.  
  46. AND cus.cCusCode is not null
  47. ;
  48.  
  49.  
  50. SELECT
  51. disp_m.bReturnFlag,
  52. dept.cDepName voucher_dept_name,
  53. disp_m.cDLCode,
  54. disp_m.dDate,
  55. cus.cCusName,
  56. disp_m.cDepCode,
  57. disp_m.cPersonCode,
  58. cus.cCusDepart,
  59. cus.cCusPPerson,
  60. new_dept.cDepName
  61.  
  62. -- update disp_m
  63. -- SET cDepCode = cus.cCusDepart,
  64. -- cPersonCode = cus.cCusPPerson
  65.  
  66. FROM DispatchList disp_m
  67.  
  68. LEFT JOIN Department dept
  69. ON disp_m.cDepCode = dept.cDepCode
  70.  
  71. LEFT JOIN Customer cus
  72. ON cus.cCusCode = disp_m.cCusCode
  73.  
  74. LEFT JOIN Department new_dept
  75. ON cus.cCusDepart = new_dept.cDepCode
  76.  
  77. WHERE disp_m.dDate >= '2023-01-01'
  78. -- AND disp_m.bReturnFlag = 0
  79. AND (
  80. dept.cDepCode = '0102'
  81. or dept.cDepName like '%停用%'
  82. )
  83.  
  84. AND cus.cCusCode is not null
  85.  
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement