declare @cnEnt int
set @cnEnt = (select top 1 entityid from vclib.T_ENTITIES where EntName = 'CARD_NOTE')
declare @EntSet int


 -- AKUZ.T_CDA_HOSPITAL_EPICRIS
set @EntSet = (select top 1 entityid from vclib.T_ENTITIES where EntName = 'CN_PDF')
update mr
set type_ = @EntSet
from AKUZ.T_MEDICAL_RECORD mr inner join AKUZ.T_CARD_NOTE cn on cn.MedicalRecordID = mr.MedicalRecordID left join AKUZ.T_EMDR_DOC_TYPE edt on cn.EmdrDocType = edt.EmdrDocTypeID
where type_ = @cnEnt and (edt.IsSemd = 0 or edt.IsSemd is null )

