Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- SELECT
- *
- INTO db_backup.dbo.rdrecord32_20230131
- FROM rdrecord32
- ;
- SELECT
- *
- INTO db_backup.dbo.DispatchList_20230131
- FROM DispatchList
- ;
- */
- SELECT
- dept.cDepName voucher_dept_name,
- rd32_m.cCode,
- rd32_m.dDate,
- cus.cCusName,
- rd32_m.cDepCode,
- rd32_m.cPersonCode,
- cus.cCusDepart,
- cus.cCusPPerson,
- new_dept.cDepName
- -- update rd32_m
- -- SET cDepCode = cus.cCusDepart,
- -- cPersonCode = cus.cCusPPerson
- FROM rdrecord32 rd32_m
- LEFT JOIN Department dept
- ON rd32_m.cDepCode = dept.cDepCode
- LEFT JOIN Customer cus
- ON cus.cCusCode = rd32_m.cCusCode
- LEFT JOIN Department new_dept
- ON cus.cCusDepart = new_dept.cDepCode
- WHERE rd32_m.dDate >= '2023-01-01'
- -- AND rd32_m.bTransFlag = 0
- AND (
- dept.cDepName like '%停用%'
- or dept.cDepCode = '0102'
- )
- AND cus.cCusCode is not null
- ;
- SELECT
- disp_m.bReturnFlag,
- dept.cDepName voucher_dept_name,
- disp_m.cDLCode,
- disp_m.dDate,
- cus.cCusName,
- disp_m.cDepCode,
- disp_m.cPersonCode,
- cus.cCusDepart,
- cus.cCusPPerson,
- new_dept.cDepName
- -- update disp_m
- -- SET cDepCode = cus.cCusDepart,
- -- cPersonCode = cus.cCusPPerson
- FROM DispatchList disp_m
- LEFT JOIN Department dept
- ON disp_m.cDepCode = dept.cDepCode
- LEFT JOIN Customer cus
- ON cus.cCusCode = disp_m.cCusCode
- LEFT JOIN Department new_dept
- ON cus.cCusDepart = new_dept.cDepCode
- WHERE disp_m.dDate >= '2023-01-01'
- -- AND disp_m.bReturnFlag = 0
- AND (
- dept.cDepCode = '0102'
- or dept.cDepName like '%停用%'
- )
- AND cus.cCusCode is not null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement