update vsame
set vsame.OutcomeRecord = v.OutcomeRecord
from AKUZ.T_DOCTOR_INSPECTION_RE re
join AKUZ.T_VISIT vsame on vsame.VisitID = re.VisitID
join AKUZ.T_VISIT v on v.VisitID = re.DoctorInspection
where v.OutcomeRecord is not null and vsame.OutcomeRecord is null

declare 
	@idJob uniqueidentifier = newid(), 
	@idSchedulerOperation uniqueidentifier = newid()
insert into vclib.T_JOB (JobID, [Name], ConcurrentExecute, JobUser)
	values (@idJob, 'Заполнение исходов у повторных осмотров', 0, null)
insert into vclib.t_SCHEDULER_OPERATION (OperationID, [Name], type_, ProcessName)
	values (@idSchedulerOperation, 'UpdateDoctorInspectionReProcess', (select EntityID from vclib.t_entities where EntName = 'RUN_PROCESS_OPERATION'), 'UpdateDoctorInspectionReProcess')
insert into vclib.T_JOB_STEP (JobStepID, Step, ContinueOnError, Job, Operation)
     VALUES (newid(), 1, 0, @idJob, @idSchedulerOperation)
insert into vclib.T_JOB_SCHEDULE(ScheduleID, Job, Mask, StartDate, EndDate, Recurs, StartTime, [Enabled], [Type], Occurs, [Servers])
	values (newid(), @idJob, null, GETDATE(), null, 1, '2024-01-01 01:00:00.000', 1, 2, 0, null)
