ประมาณนี้ครับ ลองเอาไปเป็นตัวอย่าง
begin
GetDateRangeDialog(td1, td2);
ds1:=formatdatetime('yyyy-mm-dd',td1);
ds2:=formatdatetime('yyyy-mm-dd',td2);
d1:=ds1;
d2:=ds2;
m:=getMultiplelist('select village_name from village ');
h :=getMultiplelist('select person_visit_type_name from person_visit_type ');
ChangeReportSQL('select p.person_id,concat(p.pname,p.fname," ",p.lname) as fullname,p.cid, '+
' v.village_moo as moo,v.village_name,h.address as adress,pv.*,pt.person_visit_type_name '+
' from person p '+
' left outer join house h on p.house_id=h.house_id '+
' left outer join village v on v.village_id=h.village_id '+
' left outer join person_visit pv on pv.person_id=p.person_id '+
' left outer join person_visit_type pt on pt.person_visit_type_id=pv.person_visit_type_id '+
' where pv.visit_date between "'+ds1+'" and "'+ds2+'" '+
' and p.death <> "Y" '+
' and v.village_name in ('+m+') '+
' and pt.person_visit_type_name in ('+h+') order by v.village_moo,pv.visit_date ');
end;