--The ID of the instance
declare @bpInstanceId int=1490871
-- The ID of the current step
declare @currentStepId int=15
declare @instanceId int
declare @processId int
declare @stepStartDate nvarchar(50)
declare @stepFinishDate nvarchar(50) = GETUTCDATE()
select @instanceId=instance_id, @processId=current_process_id,@stepStartDate=update_date from [dbo].cf_bp_worker_instances where bp_instance_id=@bpInstanceId and current_step_id=@currentStepId
-- set worker instance status to complete
update cf_bp_worker_instances set status=8 where instance_id=@instanceId
-- set worker instance history status to complete
if not exists (select * from [dbo].[cf_bp_worker_instance_history] where instance_id = @instanceId and step_id=@currentStepId )
-- insert worker instance history if no history exist
insert into [dbo].cf_bp_worker_instance_history(instance_id,process_id ,step_id,start_date,finish_date,status ,submission_id ,external_op,external_op_data1 ,archived_worker_instnc_to_resume,current_priority)values(@instanceId,@processId,@currentStepId,@stepStartDate,@stepFinishDate,'complete',NULL,NULL,NULL,NULL,0)
else
update[dbo].cf_bp_worker_instance_history set status='complete' where instance_id = @instanceId and step_id =@currentStepId
-- set the main instance status to complete
update [dbo].[cf_bp_main_instances] set status=2 where bp_instance_id=@bpInstanceId
Please backup your database before run the above queries.