UPDATE CARI_HESAPLAR
SET cari_cari_kilitli_flg =
CASE WHEN
NOT EXISTS(SELECT * FROM CARI_HESAP_HAREKETLERI
where cha_evrak_tip='1' and cha_tip='1'
AND cha_normal_Iade='0' and
(cha_cinsi='0' or cha_cinsi='1')
AND cha_tarihi>=DATEADD(DAY,-45,GETDATE())
AND cha_kod=cari_kod)
THEN 1
ELSE cari_cari_kilitli_flg
END
where cari_baglanti_tipi='0'
,