
			select 
				ttq.TimetableQuoteRule_id as "TimetableQuoteRule_id",
				ttq.TimetableQuoteType_id as "TimetableQuoteType_id",
				ttq.LpuUnit_id as "LpuUnit_id",
				lu.LpuUnit_Name as "LpuUnit_Name",
				ttq.LpuSectionProfile_id as "LpuSectionProfile_id",
				ttq.LpuSection_id as "LpuSection_id",
				ttq.MedStaffFact_id as "MedStaffFact_id",
				ttqt.TimetableQuoteType_Name as "TimetableQuoteType_Name",
				case 
					when ttq.LpuSectionProfile_id is not null then 'Профиль: '||lsp.LpuSectionProfile_Name
					when ttq.MedStaffFact_id is not null then 'Врач: '||msf.Person_FIO||coalesce(' ['||msf_ls.LpuSection_Code::varchar||'. '||msf_ls.LpuSection_Name||']', '')
					when ttq.LpuSection_id is not null then 'Отделение: '||ls.LpuSection_Name
					when ttq.Resource_id is not null and ttq.MedService_id is not null then 'Ресурс: '||res.Resource_Name||coalesce(' ['||ms.MedService_Nick||']', '')
					when ttq.UslugaComplex_id is not null or ttq.MedService_id is not null then 'Служба: '||coalesce(ms2.MedService_Name, '')||coalesce(' ['||uc.UslugaComplex_Name||']', '')
				end
				 as "TimetableQuote_Object",
				to_char(ttq.TimetableQuoteRule_begDT, 'DD.MM.YYYY') as "TimetableQuoteRule_begDT",
				to_char(ttq.TimetableQuoteRule_endDT, 'DD.MM.YYYY') as "TimetableQuoteRule_endDT",
				substring(ttqs.Subject, 0, length(ttqs.Subject)) as "TimetableQuoteSubjects"
			from
			    v_TimetableQuoteRule ttq
				left join v_LpuUnit lu on ttq.LpuUnit_id = lu.LpuUnit_id
				left join v_LpuSectionProfile lsp on ttq.LpuSectionProfile_id = lsp.LpuSectionProfile_id
				left join v_LpuSection ls on ttq.LpuSection_id = ls.LpuSection_id
				left join v_MedStaffFact msf on ttq.MedStaffFact_id = msf.MedStaffFact_id
				left join v_LpuSection msf_ls on msf.LpuSection_id = msf_ls.LpuSection_id
				left join v_Resource res on res.Resource_id = ttq.Resource_id
				left join v_MedService ms on ms.MedService_id = res.MedService_id
				left join v_MedService ms2 on ms2.MedService_id = ttq.MedService_id
				left join v_UslugaComplex uc on uc.UslugaComplex_id = ttq.UslugaComplex_id
				left join lateral (
					select
						(
							select string_agg(coalesce(l.Lpu_Nick, et.ERTerr_Name, msf.Person_FIO, lr.LpuRegion_Name, ls.LpuSection_Name)||' - '||ttqs2.TimetableQuote_Amount::varchar||'|', '') 
							from
							    v_TimetableQuoteRuleSubject ttqs2
								left join v_Lpu l on ttqs2.Lpu_id = l.Lpu_id
								left join v_ERTerr et on ttqs2.ERTerr_id = et.ERTerr_id
								left join v_MedStaffFact msf on ttqs2.MedStaffFact_id = msf.MedStaffFact_id
								left join v_LpuSection ls on ttqs2.LpuSection_id = ls.LpuSection_id
								left join v_LpuRegion lr on ttqs2.LpuRegion_id = lr.LpuRegion_id
							where ttqs2.TimetableQuoteRule_id = ttqs1.TimetableQuoteRule_id
						) as Subject
					from v_TimetableQuoteRuleSubject ttqs1
					where ttqs1.TimetableQuoteRule_id = ttq.TimetableQuoteRule_id
				) as ttqs on true
				left join TimetableQuoteType ttqt on ttq.TimetableQuoteType_id = ttqt.TimetableQuoteType_id
			where ttq.Lpu_id = '26' and ttq.LpuUnit_id = '450101000001240' and '2022-01-19' between ttq.TimetableQuoteRule_begDT and ttq.TimetableQuoteRule_endDT
		
