update QualityMonitoringGoods set materialDefinitionId = (select min(id) from MaterialDefinition where QualityMonitoringGoods.material = case when specification is null or specification = '' then name else name + '['+ specification +']' end) where material is not null and material <> '' and materialDefinitionId is null;