update recyclingapplication set lastReturnDateTime = (select max(ip.applicationtime) from recyclingapplication ra join InvoicePlan ip on ip.id = ra.id where ra.recyclingApplication_id = recyclingapplication.id) where id in (select id from InvoicePlan where type = '借物单') and lastReturnDateTime is null; update recyclingapplication set lastReturnDateTime = (select CONVERT(datetime, substring(remark, CHARINDEX(remark,'【该申请单在', 0) + 7, 19), 120) from InvoicePlan where id = recyclingapplication.id) where id in (select id from InvoicePlan where type = '借物单' and remark like '【该申请单在%被%通过完全归还完成】%') and lastReturnDateTime is null;