update ReturnMaterialRecord set settleAccountsDepartCoding = (select orgUnitCoding from SupplyRoomConfig where supplyRoomType = 4 and orgUnitCoding = (select settleAccountsDepartCoding from SupplyRoomConfig where supplyRoomType = 3 and orgUnitCoding = ReturnMaterialRecord.departCoding and settleAccountsDepartCoding is not null and settleAccountsDepartCoding <> '')) where settleAccountsDepartCoding is null;
update ReturnMaterialRecord set settleAccountsDepart = (select orgUnitName from SupplyRoomConfig where supplyRoomType = 4 and orgUnitCoding = (select settleAccountsDepartCoding from SupplyRoomConfig where supplyRoomType = 3 and orgUnitCoding = ReturnMaterialRecord.departCoding and settleAccountsDepartCoding is not null and settleAccountsDepartCoding <> '')) where settleAccountsDepart is null;
update ReturnMaterialRecord set settleAccountsDepartCoding = departCoding, settleAccountsDepart = depart where settleAccountsDepartCoding is null and settleAccountsDepart is null;
update MaterialInvoice set settleAccountsDepartCoding = (select orgUnitCoding from SupplyRoomConfig where supplyRoomType = 4 and orgUnitCoding = (select settleAccountsDepartCoding from SupplyRoomConfig where supplyRoomType = 3 and orgUnitCoding = MaterialInvoice.departCoding and settleAccountsDepartCoding is not null and settleAccountsDepartCoding <> '')) where settleAccountsDepartCoding is null;
update MaterialInvoice set settleAccountsDepart = (select orgUnitName from SupplyRoomConfig where supplyRoomType = 4 and orgUnitCoding = (select settleAccountsDepartCoding from SupplyRoomConfig where supplyRoomType = 3 and orgUnitCoding = MaterialInvoice.departCoding and settleAccountsDepartCoding is not null and settleAccountsDepartCoding <> '')) where settleAccountsDepart is null;
update MaterialInvoice set settleAccountsDepartCoding = departCoding, settleAccountsDepart = depart where settleAccountsDepartCoding is null and settleAccountsDepart is null;
