select
		 
		/*Common*/
		PersonState.Person_id as id,
		/*Audited*/
		Person.pmUser_insID,
		Person.pmUser_updID,
		Person.Person_insDT as insDT,
		Person.Person_updDT as updDT,
		/*Person*/
		Person.Person_IsUnknown,
		Person.Person_Guid,
		Person.BDZ_id as Person_BdzId,
		rtrim(ltrim(PersonState.Person_SurName)) as Person_SurName,
		rtrim(ltrim(PersonState.Person_FirName)) as Person_FirName,
		rtrim(ltrim(PersonState.Person_SecName)) as Person_SecName,
		PersonState.Person_BirthDay,
		rtrim(ltrim(PersonState.Person_Snils)) as Person_Snils,
		rtrim(ltrim(PersonState.Person_Inn)) as Person_Inn,
		rtrim(ltrim(PersonState.Person_Phone)) as Person_Phone,
		PersonState.Sex_id as Sex_id,
		PersonState.SocStatus_id,
		PersonState.KLCountry_id as NationalityCountryId,
		PersonState.NationalityStatus_IsTwoNation,
		case when PersonState.PersonCloseCause_id = 1 then PersonState.Person_deadDT else NULL end as Person_deadDT,
		Person.Person_IsDead,
		Polis.Polis_id,
		Polis.Polis_Guid,
		Polis.BDZ_id as Polis_BdzId,
		Polis.PolisType_id,
		Polis.PolisFormType_id,
		Polis.PolisCloseCause_id,
		 
				case when Polis.PolisType_id != 4 then nullif(rtrim(ltrim(Polis.Polis_Ser)), '') else null end as Polis_Ser,
				case when Polis.PolisType_id != 4 then nullif(rtrim(ltrim(Polis.Polis_Num)), '') else null end as Polis_Num,
			 
		Polis.OMSSprTerr_id,
		Polis.Polis_begDate,
		Polis.Polis_endDate,
		Polis.Polis_planDate,
		case when Polis.PolisType_id = 4 then rtrim(ltrim(PersonState.Person_EdNum)) else null end as Person_EdNum,
		OrgSmo.OrgSmo_id,
		OrgSmo.Orgsmo_f002smocod,
		OrgSmo.OrgSmo_fedId,
		rtrim(ltrim(OrgSmo.OrgSmo_Name)) as OrgSmo_Name,
		rtrim(ltrim(OrgSmo.OrgSmo_Nick)) as OrgSmo_Nick,
		Document.Document_id,
		Document.DocumentType_id,
		nullif(rtrim(ltrim(Document.Document_Ser)), '') as Document_Ser,
		nullif(rtrim(ltrim(Document.Document_Num)), '') as Document_Num,
		Document.Document_begDate,
		Document.Document_endDate,
		Document.KLCountry_id,
		Document.OrgDep_Text as OrgDepText,
		PersonState.UAddress_id,
		PersonState.PAddress_id,
		Job.Job_id,
		Job.PersonJob_begDate,
		Job.PersonJob_endDate,
		rtrim(ltrim(Job.Job_nfData)) as Job_nfData,
		Post.Post_id,
		rtrim(ltrim(Post.Post_Name)) as Post_Name,
		JobOrg.Org_id,
		JobOrg.Org_Code,
		rtrim(ltrim(JobOrg.Org_Name)) as Org_Name,
		rtrim(ltrim(JobOrg.Org_Nick)) as Org_Nick,
		PersonState.FamilyStatus_id,
		PersonBirthPlace.Address_id as BAddress_id,
		OrgDep.Org_id as OrgDep_id,
		OrgDep.Org_Name as OrgDep_Name
	 
		from dbo.v_PersonState PersonState  
		 
		inner join dbo.v_Person Person   on PersonState.Person_id = Person.Person_id
		left join dbo.v_Polis Polis   on PersonState.Polis_id = Polis.Polis_id
		left join dbo.v_OrgSMO OrgSmo   on Polis.OrgSmo_id = OrgSMO.OrgSMO_id
		left join dbo.v_Document Document   on PersonState.Document_id = Document.Document_id
		left join dbo.v_Job Job   on PersonState.Job_id = Job.Job_id
		left join dbo.v_Post Post   on Job.Post_id = Post.Post_id
		left join dbo.v_Org JobOrg   on Job.Org_id = JobOrg.Org_id
		left join dbo.v_PersonBirthPlace PersonBirthPlace   on PersonState.Person_id = PersonBirthPlace.Person_id
		left join dbo.v_OrgDep OrgDep   on Document.OrgDep_id = OrgDep.OrgDep_id
	 
		where (1 = 1)
		 
		 
		 
			and PersonState.Person_SurNameR = dbo.PersonNameR($1)
		 
		 
			and PersonState.Person_FirNameR = dbo.PersonNameR($2)
		 
		 
			and PersonState.Person_SecNameR = dbo.PersonNameR($3)
		 
		 
		 
			and PersonState.Sex_id = $4
