
                with E as (
                    select * from v_Evn E
                    where E.Evn_pid = '120101133953801'
                    and E.Evn_setDT >= '2014-12-01'
                )
                select E.Evn_id as "Evn_id"
                from E
                    inner join r12.v_RegistryData RD on RD.Evn_id = E.Evn_id
                    inner join r12.v_Registry R on RD.Registry_id = R.Registry_id
                where (
                    R.RegistryStatus_id not in (4)
                    or (R.RegistryStatus_id = 4 and RD.RegistryData_IsPaid = 2)
                )
                limit 1
            
