if preset_value(1)='' then
begin
if not inputquery('อายุตั้งแต่ ','อายุตั้งแต่',age1) then exit;
end else
begin
age1:='');
end;
if preset_value(2)='' then
begin
if not inputquery('ถึงอายุ','ถึงอายุ',age2) then exit;
end else
begin
age2:='');
end;
//showmessage('อายุ1 = '+age1+' อายุ2 ช'+age2);
sex_list := getpickuplist('select concat(code,":",name) as name from sex ');
fcds2.datarequest('select concat(p.age_y," ปี ",p.age_m," ด.")as agefull,h.village_id,h.address,concat(p.pname," ",p.fname," ",p.lname)as pttname,p.* ,pc.name as pttype_name, '+
' x.name as sex_name ,n.name as nationality_name, concat(p2.fname," ",p2.lname) as father_name , concat(p3.fname," ",p3.lname) as mother_name '+
' , concat(p4.fname," ",p4.lname) as couple_name , e.name as education_name ,o.name as occupation_name,r.name as religion_name , '+
' y.name as marrystatus_name ,t.house_regist_type_name , f.family_no , pp.person_house_position_name from person p '+
' left outer join house h on h.house_id = p.house_id '+
' left outer join pttype pc on pc.pttype = p.pttype '+
' left outer join sex x on x.code = p.sex left outer join nationality n on n.nationality = p.nationality '+
' left outer join education e on e.education = p.education left outer join occupation o on o.occupation = p.occupation '+
' left outer join religion r on r.religion = p.religion left outer join marrystatus y on y.code = p.marrystatus '+
' left outer join person p2 on p2.person_id = p.father_person_id '+
' left outer join person p3 on p3.person_id = p.mother_person_id '+
' left outer join person p4 on p4.person_id = p.couple_person_id '+
' left outer join person_house_position pp on pp.person_house_position_id = p.person_house_position_id '+
' left outer join family f on f.family_id = p.family_id '+
' left outer join house_regist_type t on t.house_regist_type_id = p.house_regist_type_id '+
' where p.age_y between "'+age1+'" and "'+age2+'" and p.village_id="'+copy(hospcode_list,1,2)+'" and p.sex="'+copy(sex_list,1,1)+'" and p.death = "N" order by p.person_id ');