
			update
				EvnStickWorkRelease eswr
			set
                EvnStickWorkRelease_IsInReg = case when COALESCE(eswr.EvnStickWorkRelease_IsPaid, 1) = 1 and not  (0=1)  then 1 else eswr.EvnStickWorkRelease_IsInReg end, -- снимаем IsInReg, если IsPaid <> 2 и есть ошибки
                EvnStickWorkRelease_IsPaid = case when eswr.EvnStickWorkRelease_IsInReg = 2 and  (0=1)  then 2 else eswr.EvnStickWorkRelease_IsPaid end -- ставим IsPaid = 2, если IsInReg = 2 и нет ошибок
			from
				v_RegistryESData resd
			where
				resd.RegistryES_id = '520101000012197'
				and resd.SecondEvnStickWorkRelease_id = eswr.EvnStickWorkRelease_id
				
		
