-- 插入字典code


declare @TrialCriterionId uniqueidentifier='54650000-3E2C-0016-75E6-08DB320098F3'

insert TrialCriterionDictionaryCode (Id,TrialCriterionId,Code,CreateTime,CreateUserId) 
select NEWID(), 
@TrialCriterionId,Code,'2020-01-01','00000000-0000-0000-0000-000000000000' from SystemCriterionDictionaryCode 
                                                          
inner join ReadingQuestionCriterionTrial on   SystemCriterionDictionaryCode.SystemCriterionId=ReadingQuestionCriterionTrial.ReadingQuestionCriterionSystemId and ReadingQuestionCriterionTrial.Id=
@TrialCriterionId

where Code not in (select Code from  TrialCriterionDictionaryCode  where TrialCriterionId=
@TrialCriterionId)

-- 插入字典
insert into ReadingCriterionDictionary (Id,CriterionId,DictionaryId,CreateTime,CreateUserId,IsSystemCriterion,ParentCode,IsBaseLineUse,IsFollowVisitUse)

select NEWID(), @TrialCriterionId,DictionaryId,'2020-01-01','00000000-0000-0000-0000-000000000000',0,ParentCode,IsBaseLineUse,IsFollowVisitUse from ReadingCriterionDictionary 
                                                          
inner join ReadingQuestionCriterionTrial on   ReadingCriterionDictionary.CriterionId=ReadingQuestionCriterionTrial.ReadingQuestionCriterionSystemId and ReadingQuestionCriterionTrial.Id=
@TrialCriterionId

where DictionaryId not in (select DictionaryId from  ReadingCriterionDictionary  where CriterionId=
@TrialCriterionId)
