
                    update
                        RegistryESData resd
                    set
                        RegistryESDataStatus_id = (case when exists(
                            select
                                Evn_id
                            from
                                v_RegistryESError REEs
                            where
                                REEs.Evn_id = resd.Evn_id
                                and REEs.RegistryES_id = resd.RegistryES_id
                            limit 1
                        ) then 3 else 2 end)
                    where
                        resd.RegistryES_id = '140101000082652'
                        and COALESCE(resd.RegistryESDataStatus_id,1) in (1,2)
                
