code ที่อยู่ในรายงานหลักครับ ไม่ทราบว่าต้อง แก้ตรงไหนบ้างครับ
//SQL
select * from tempreport where id = "{onlineid}"
and num1>0
order by name,name2
//Script
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;
people_distinct_count1 : integer;
people_count1 : integer;
ds1,ds2:string;
pttype_list1 : string;
fonlineid:string;
i:integer;
money1:currency;
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);
fonlineid:=report_value(1);
zquery.sql.text:='delete from tempreport where id = "'+fonlineid+'" ';
zquery.execsql;
fcds.close;
fcds.datarequest('select * from tempreport where id = "'+fonlineid+'" limit 0 ');
fcds.open;
fcds2.close;
fcds2.datarequest('select * from doctor ');
fcds2.open;
setprogressbar(0,fcds2.recordcount);
fcds2.first;
i:=0;
while not fcds2.eof do
begin
i:=i+1;
setprogressbar(i,fcds2.recordcount);
fcds3.close;
fcds3.datarequest('select t.code,t.name,count(m.vn) as vn_count ,sum(m.tcount) as t_count'+
' , sum(m.scount) as s_count '+
' from dttm t '+
' left outer join dtmain m on m.tmcode=t.code '+
' and m.doctor="'+fcds2.fieldbyname('code').asstring+'" '+
' and m.vstdate between "'+ds1+'" and "'+ds2+'" '+
' group by t.code,t.name ');
fcds3.open;
while not fcds3.eof do
begin
fcds.insert;
fcds['id']:=fonlineid;
fcds['reportname']:='CUSTOM-Doctor1';
try
fcds['name']:=fcds2['name'];
fcds['name2']:=fcds3['code'];
fcds['name3']:=fcds3['name'];
fcds['num1']:=fcds3['vn_count'];
fcds['num2']:=fcds3['t_count'];
fcds['num3']:=fcds3['s_count'];
except end;
fcds['date1']:=d1;
fcds['date2']:=d2;
if fcds.fieldbyname('num1').asinteger>0 then
fcds.post else
fcds.cancel;
fcds3.next;
end;
fcds.datarequest('select * from tempreport where id = "'+fonlineid+'" limit 0 ');
applyupdate_fcds();
fcds2.next;
end;
fcds3.close;
fcds.datarequest('select * from tempreport where id = "'+fonlineid+'" limit 0 ');
applyupdate_fcds();
end;
end.