insert into TousseDefinitionNote (note, tousseDefinitionId) select note, id from TousseDefinition where forDisplay = 1 and len(note)>0; update TousseDefinition set note_id = (select id from TousseDefinitionNote where tousseDefinitionId = TousseDefinition.id); update UseRecord set departCodeOfpatient = (select top 1 orgUnitCoding from OrgUnit where name = UseRecord.ascriptionDepartment) where (departCodeOfpatient is null or departCodeOfpatient = '') and ascriptionDepartment is not null and ascriptionDepartment <> ''; update UseRecord set departCodeOfpatient = (select top 1 orgUnitCoding from OrgUnit where orgUnitCoding = UseRecord.ascriptionDepartment) where (departCodeOfpatient is null or departCodeOfpatient = '') and ascriptionDepartment is not null and ascriptionDepartment <> '';