
			update
				EvnStickBase esb
			set
                EvnStickBase_IsInReg = case when COALESCE(esb.EvnStickBase_IsPaid, 1) = 1 and not  (0=1)  then 1 else esb.EvnStickBase_IsInReg end, -- снимаем IsInReg, если IsPaid <> 2 и есть ошибки

                EvnStickBase_IsPaid = case when esb.EvnStickBase_IsInReg = 2 and  (0=1)  then 2 else esb.EvnStickBase_IsPaid end -- ставим IsPaid = 2, если IsInReg = 2 и нет ошибок
			from
				v_RegistryESData resd
			where
				resd.RegistryES_id = '520101000014844'
				and resd.Evn_id = esb.Evn_id
				
		
