ผมทำรายงานเด็กเกิดใหม่ครับ เป็น Custom Report
โดยให้สามารถเลือกช่วงวันที่ที่ต้องการดึงข้อมูลได้
แต่พบปัญหาว่า หากมีวันไหนที่ไม่มีข้อมูล เพียงแค่วันเดียว มันก็จะไม่แสดงข้อมูลที่เหลือเลย
ไม่ทราบว่าจะทำอย่างไรดีครับ
ผมแนบไฟล์รายงานมาด้วยครับ
unit MyIPDReport;
function getsqlsubquerydata(sql:string):string;
begin
result:='';
zquery.close;
zquery.sql.text:=sql;
zquery.open;
zquery.first;
while not zquery.eof do
begin
if result='' then result:=''''+zquery.fields[0].asstring+'''' else
result:=result+','''+zquery.fields[0].asstring+'''';
zquery.next;
end;
zquery.close;
if result='' then result:='''''';
end;
procedure main;
var d1,d2:tdatetime;
ds1,ds2,tambon,ampur,chw:string;
begin
if not getdaterange() then exit;
d1:=date_result1();
d2:=date_result2();
// showmessage(formatdatetime('yyyy-mm-dd',d1)+' - '+
// formatdatetime('yyyy-mm-dd',d2));
ds1:=formatdatetime('yyyy-mm-dd',d1);
ds2:=formatdatetime('yyyy-mm-dd',d2);
zquery.sql.text:='delete from tempreport where id = "CUSTOM-PCU-INFANT" ';
zquery.execsql;
fcds.close;
fcds.datarequest('select * from tempreport where id = "CUSTOM-PCU-INFANT" ');
fcds.open;
fcds2.close;
fcds2.datarequest('select * from ipt_labour_infant i left outer join ipt_labour l on l.ipt_labour_id=i.ipt_labour_id where i.birth_date between "'+ds1+'" and "'+ds2+'" order by i.ipt_labour_infant_id asc');
fcds2.open;
while not fcds2.eof do
begin
fcds.insert;
fcds['id']:='CUSTOM-PCU-INFANT';
fcds['reportname']:='CUSTOM-PCU-INFANT';
fcds['num']:=fcds2['ipt_labour_infant_id'];
fcds['num1']:=fcds2['birth_weight'];
fcds['name']:=fcds2['an'];
fcds['name1']:=getsqldata('select hn from ipt where an=(select an from ipt_newborn where mother_an='+fcds2['an']+')');
fcds['name2']:=getsqldata('select concat(pname,fname," ",lname) as paname from patient where hn='+fcds['name1']);
fcds['name3']:=getsqldata('select concat(fathername," ",fatherlname) as fathername from patient where hn='+fcds['name1']);
fcds['name4']:=getsqldata('select concat(mathername," ",motherlname) as mothername from patient where hn='+fcds['name1']);
tambon :=getsqldata('select tmbpart from patient where hn='+fcds['name1']);
ampur :=getsqldata('select amppart from patient where hn='+fcds['name1']);
chw :=getsqldata('select chwpart from patient where hn='+fcds['name1']);
fcds['name5']:=getsqldata('select concat(addrpart," ËÁÙè ",moopart'+
'," µ.",(select name from thaiaddress where codetype=3 and chwpart='+chw+' and amppart='+ampur+' and tmbpart='+tambon+')'+
'," Í.",(select name from thaiaddress where codetype=2 and chwpart='+chw+' and amppart='+ampur+')'+
'," ¨.",(select name from thaiaddress where codetype=1 and chwpart='+chw+'))'+
' as address from patient where hn='+fcds['name1']);
fcds['name6']:=fcds2['infant_check_vitk'];
fcds['name7']:=fcds2['infant_check_eyepaste'];
fcds['name8']:=formatdatetime('HH:mm',fcds2['birth_time']);
fcds['date1']:=d1;
fcds['date2']:=d2;
fcds['date3']:=fcds2['birth_date'];
fcds.post;
fcds2.next;
end;
fcds.datarequest('select * from tempreport where id = "CUSTOM-PCU-INFANT" ');
applyupdate_fcds();
end;
end.