select * into TousseInstanceId_WashRecordId from (select top 10000 ti.id tousseInstanceId, max(wdr.id) washRecordId from WashAndDisinfectRecord wdr join ClassifyBasket_WashRecord cbwr on cbwr.WashAndDisinfectRecord_ID = wdr.id join ClassifyBasket_RecyclingRecord cbrr on cbrr.ClassifyBasket_ID = cbwr.ClassifyBasket_ID join TousseInstance ti on ti.recyclingRecordId = cbrr.RecyclingRecord_ID where ti.packingRecord_id is null and ti.disinfectProgram is null group by ti.id) rs;
select * into TousseInstanceWashRecordTable from (select tousseInstanceId, wdr.disinfectIdentification, wdr.disinfectProgram, wdr.operatorCode, wdr.operator, CONVERT(varchar(100),wdr.startDate,120) startDateStr, CONVERT(varchar(100),wdr.endDate,120) endDateStr from TousseInstanceId_WashRecordId tiwdr join WashAndDisinfectRecord wdr on wdr.id = tiwdr.washRecordId) rs;
update TousseInstance set disinfectIdentification = (select disinfectIdentification from TousseInstanceWashRecordTable po where po.tousseInstanceId = TousseInstance.id), disinfectProgram = (select disinfectProgram from TousseInstanceWashRecordTable po where po.tousseInstanceId = TousseInstance.id), washOperatorCode = (select operatorCode from TousseInstanceWashRecordTable po where po.tousseInstanceId = TousseInstance.id), washOperator = (select operator from TousseInstanceWashRecordTable po where po.tousseInstanceId = TousseInstance.id), washStartTime = (select startDateStr from TousseInstanceWashRecordTable po where po.tousseInstanceId = TousseInstance.id), washEndTime = (select endDateStr from TousseInstanceWashRecordTable po where po.tousseInstanceId = TousseInstance.id) where id in (select tousseInstanceId from  TousseInstanceWashRecordTable);
update Tousseinstance set recyclingOperator = (select operator from Recyclingrecord where id = Tousseinstance.Recyclingrecordid), recyclingUser = (select recyclingUser from Recyclingrecord where id = Tousseinstance.Recyclingrecordid) where id in (select tousseInstanceId from  TousseInstanceWashRecordTable);
drop table TousseInstanceId_WashRecordId;
drop table TousseInstanceWashRecordTable;