declare @cnpdf int
set @cnpdf = (select top 1 entityid from vclib.T_ENTITIES where EntName = 'CN_PDF')

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

select cn.MedicalRecordID into #temp from akuz.T_MEDICAL_RECORD mr 
	join AKUZ.T_CARD_NOTE cn on mr.MedicalRecordID = cn.MedicalRecordID
	join AKUZ.T_RECIPE r on r.MedicalRecordID = cn.AmbulanceCardRecord
where type_ = @cn

update mr
set type_ = @cnpdf
from akuz.T_MEDICAL_RECORD mr join #temp t on t.MedicalRecordID = mr.MedicalRecordID
GO