declare @typeId int = (select EntityId from vclib.T_ENTITIES where EntName = 'ROUTE_MAP_REPRODUCTIVE')
insert into AKUZ.T_ROUTE_MAP_REPRODUCTIVE
select anketa.MedicalRecordID, 0 from AKUZ.T_ANKETA anketa
join akuz.T_MEDICAL_RECORD record on record.MedicalRecordID = anketa.MedicalRecordID
where record.type_ = @typeId
and NOT EXISTS
(
	select 1 from AKUZ.T_ROUTE_MAP_REPRODUCTIVE repr
	where repr.MedicalRecordID = anketa.MedicalRecordID
) 