
			select * from (select
				EvnXml.Evn_id as "EvnXml_pid",
				Evn.Evn_pid as "Evn_pid",
				Evn.Evn_rid as "Evn_rid",
				Evn.EvnClass_id as "EvnClass_id",
				Evn.EvnClass_SysNick as "EvnClass_SysNick",
				EvnXml.XmlType_id as "XmlType_id",
				EvnXml.EvnXml_id as "EvnXml_id",
				EvnXml.EvnXml_Name as "EvnXml_Name",
				EvnXml.EvnXml_IsSigned as "EvnXml_IsSigned",
			    EvnXml.EvnXml_id as "EMDRegistry_ObjectID",
			    EvnXml.XmlTemplate_id as "XmlTemplate_id",   
				'EvnXml' as "EMDRegistry_ObjectName",
				to_char (EvnXml.EvnXml_insDT, 'dd.mm.yyyy') as "EvnXml_Date",
				EvnXml.pmUser_insID as "pmUser_insID",
				RTRIM(LTRIM(COALESCE(pmUserCache.pmUser_Name, ''))) as "pmUser_Name",
				0 as "frame",
				to_char(coalesce(EvnXml.EvnXml_setDT, EvnXml.EvnXml_insDT), 'DD.MM.YYYY HH24:MI') as "EvnXml_setDT",
				to_char(coalesce(EvnXml.EvnXml_setDT, EvnXml.EvnXml_insDT), 'DD.MM.YYYY') as "EvnXml_setDTDate",
				to_char(coalesce(EvnXml.EvnXml_setDT, EvnXml.EvnXml_insDT), 'HH24:MI') as "EvnXml_setDTTime",
				to_char(coalesce(EvnXml.EvnXml_setDT, EvnXml.EvnXml_insDT), 'DD.MM.YYYY HH24:MI') as "EvnXml_DateTime",
			    xt.XmlType_Name as "XmlType_Name",
			    xt.XmlType_Code as "XmlType_Code",
				xtt.XmlTemplate_Caption as "XmlTemplate_Caption",
			    xtt.XmlTypeKind_id as "XmlTypeKind_id"
			from
				v_EvnXml EvnXml 
				inner join lateral( select Evn.Evn_pid,	Evn.Evn_rid,Evn.EvnClass_id,Evn.EvnClass_SysNick from v_Evn Evn where Evn.Evn_id = EvnXml.Evn_id limit 1) Evn on true
				left join pmUserCache  on pmUserCache.pmUser_id = EvnXml.pmUser_insID
				left join XmlTemplate xtt on xtt.XmlTemplate_id = EvnXml.XmlTemplate_id
				left join XmlTemplateData xtd  on xtd.XmlTemplateData_id = EvnXml.XmlTemplateData_id
				left join XmlTemplateHtml xth  on xth.XmlTemplateHtml_id = EvnXml.XmlTemplateHtml_id
				left join XmlTemplateSettings xts  on xts.XmlTemplateSettings_id = EvnXml.XmlTemplateSettings_id
				left join v_XmlType xt on xt.XmlType_id = EvnXml.XmlType_id
			where (1=1) and EvnXml.XmlType_id in (8, 25, 26, 17) and EvnXml.Evn_id = '500801005614073'
		
				union all
				select
					EvnXml.Evn_id as "EvnXml_pid",
					euo.EvnUslugaOper_pid as "Evn_pid",
					euo.EvnUslugaOper_rid as "Evn_rid",
					euo.EvnClass_id as "EvnClass_id",
					'EvnUslugaOper' as "EvnClass_SysNick",
					EvnXml.XmlType_id as "XmlType_id",
					EvnXml.EvnXml_id as "EvnXml_id",
					EvnXml.EvnXml_Name as "EvnXml_Name",
					EvnXml.EvnXml_IsSigned as "EvnXml_IsSigned",
					EvnXml.EvnXml_id as "EMDRegistry_ObjectID",
					EvnXml.XmlTemplate_id as "XmlTemplate_id",   
					'EvnXml' as "EMDRegistry_ObjectName",
					to_char (EvnXml.EvnXml_insDT, 'dd.mm.yyyy') as "EvnXml_Date",
					EvnXml.pmUser_insID as "pmUser_insID",
					RTRIM(LTRIM(COALESCE(pmUserCache.pmUser_Name, ''))) as "pmUser_Name",
					0 as "frame",
					to_char(EvnXml.EvnXml_setDT, 'DD.MM.YYYY HH24:MI') as "EvnXml_setDT",
					to_char(EvnXml.EvnXml_setDT, 'DD.MM.YYYY') as "EvnXml_setDTDate",
					to_char(EvnXml.EvnXml_setDT, 'HH24:MI') as "EvnXml_setDTTime",
					to_char(coalesce(EvnXml.EvnXml_setDT, EvnXml.EvnXml_insDT), 'DD.MM.YYYY HH24:MI') as "EvnXml_DateTime",
					xt.XmlType_Name as "XmlType_Name",
					xt.XmlType_Code as "XmlType_Code",
					xtt.XmlTemplate_Caption as "XmlTemplate_Caption",
			    	xtt.XmlTypeKind_id as "XmlTypeKind_id"
				from
					v_EvnXml EvnXml 
					inner join v_EvnUslugaOper euo on euo.EvnUslugaOper_id = EvnXml.Evn_id
					inner join v_EvnDirection ed on ed.EvnDirection_id = euo.EvnDirection_id
					left join pmUserCache  on pmUserCache.pmUser_id = EvnXml.pmUser_insID
					left join XmlTemplate xtt on xtt.XmlTemplate_id = EvnXml.XmlTemplate_id
					left join XmlTemplateData xtd  on xtd.XmlTemplateData_id = EvnXml.XmlTemplateData_id
					left join XmlTemplateHtml xth  on xth.XmlTemplateHtml_id = EvnXml.XmlTemplateHtml_id
					left join XmlTemplateSettings xts  on xts.XmlTemplateSettings_id = EvnXml.XmlTemplateSettings_id
					left join v_XmlType xt on xt.XmlType_id = EvnXml.XmlType_id
				where (1=1) and EvnXml.XmlType_id in (8, 25, 26, 17) and ed.EvnDirection_pid = '500801005614073' 
				) T
			order by cast("EvnXml_setDT" as timestamp) ASC
