insert	into
	pg_temp.tt115 (_Q_000_F_000_TYPE,
	_Q_000_F_000_RTRef,
	_Q_000_F_000_RRRef)
select
	T1.Fld44327_TYPE,
	T1.Fld44327_RTRef,
	T1.Fld44327_RRRef
from
	(
	select
		T6._Fld44327_TYPE as Fld44327_TYPE,
		T6._Fld44327_RTRef as Fld44327_RTRef,
		T6._Fld44327_RRRef as Fld44327_RRRef,
		T6._Fld44329 as Fld44329_
	from
		(
		select
			T3.Fld44327_TYPE as Fld44327_TYPE,
			T3.Fld44327_RTRef as Fld44327_RTRef,
			T3.Fld44327_RRRef as Fld44327_RRRef,
			T3.Fld44328RRef as Fld44328RRef,
			T3.Fld44329_ as Fld44329_,
			T3.Fld44330_ as Fld44330_,
			T3.Fld44331RRef as Fld44331RRef,
			T3.Fld44332RRef as Fld44332RRef,
			T3.MAXPERIOD_ as MAXPERIOD_,
			SUBSTR(MAX(T5._RecorderTRef || T5._RecorderRRef), 1, 4) as MAXRECORDERTRef,
			SUBSTR(MAX(T5._RecorderTRef || T5._RecorderRRef), 5, 16) as MAXRECORDERRRef
		from
			(
			select
				T4._Fld44327_TYPE as Fld44327_TYPE,
				T4._Fld44327_RTRef as Fld44327_RTRef,
				T4._Fld44327_RRRef as Fld44327_RRRef,
				T4._Fld44328RRef as Fld44328RRef,
				T4._Fld44329 as Fld44329_,
				T4._Fld44330 as Fld44330_,
				T4._Fld44331RRef as Fld44331RRef,
				T4._Fld44332RRef as Fld44332RRef,
				MAX(T4._Period) as MAXPERIOD_
			from
				_InfoRg44326 T4
			where
				((T4._Fld2507 = cast(0 as numeric)))
				and (T4._Active = true)
			group by
				T4._Fld44327_TYPE,
				T4._Fld44327_RTRef,
				T4._Fld44327_RRRef,
				T4._Fld44328RRef,
				T4._Fld44329,
				T4._Fld44330,
				T4._Fld44331RRef,
				T4._Fld44332RRef) T3
		inner join _InfoRg44326 T5 on
			T3.Fld44327_TYPE = T5._Fld44327_TYPE
			and T3.Fld44327_RTRef = T5._Fld44327_RTRef
			and T3.Fld44327_RRRef = T5._Fld44327_RRRef
			and T3.Fld44328RRef = T5._Fld44328RRef
			and T3.Fld44329_ = T5._Fld44329
			and T3.Fld44330_ = T5._Fld44330
			and T3.Fld44331RRef = T5._Fld44331RRef
			and T3.Fld44332RRef = T5._Fld44332RRef
			and T3.MAXPERIOD_ = T5._Period
		where
			((T5._Fld2507 = cast(0 as numeric)))
			and (T5._Active = true)
		group by
			T3.Fld44327_TYPE,
			T3.Fld44327_RTRef,
			T3.Fld44327_RRRef,
			T3.Fld44328RRef,
			T3.Fld44329_,
			T3.Fld44330_,
			T3.Fld44331RRef,
			T3.Fld44332RRef,
			T3.MAXPERIOD_) T2
	inner join _InfoRg44326 T6 on
		T2.Fld44327_TYPE = T6._Fld44327_TYPE
		and T2.Fld44327_RTRef = T6._Fld44327_RTRef
		and T2.Fld44327_RRRef = T6._Fld44327_RRRef
		and T2.Fld44328RRef = T6._Fld44328RRef
		and T2.Fld44329_ = T6._Fld44329
		and T2.Fld44330_ = T6._Fld44330
		and T2.Fld44331RRef = T6._Fld44331RRef
		and T2.Fld44332RRef = T6._Fld44332RRef
		and T2.MAXPERIOD_ = T6._Period
		and T2.MAXRECORDERTRef = T6._RecorderTRef
		and T2.MAXRECORDERRRef = T6._RecorderRRef
	where
		(T6._Fld2507 = cast(0 as numeric))) T1
where
	(T1.Fld44327_TYPE = '\\\\010'::bytea
		and T1.Fld44327_RTRef = '\\\\000\\\\000\\\\004\\\\313'::bytea)
	and exists(select 1 from pg_temp.tt135 T7 where (T1.Fld44327_TYPE = T7._Q_001_F_000_TYPE and T1.Fld44327_RTRef = T7._Q_001_F_000_RTRef and T1.Fld44327_RRRef = T7._Q_001_F_000_RRRef))
group by
	T1.Fld44327_TYPE,
	T1.Fld44327_RTRef,
	T1.Fld44327_RRRef

