ลองใช้คำสั่งนี้ ไปเขียนรายงานดูครับ
GetDateRangeDialog(d1, d2);
ds1:=formatdatetime('yyyy-mm-dd',d1);
ds2:=formatdatetime('yyyy-mm-dd',d2);
suchat:= GetPickupList('select department from kskdepartment');
ChangeReportSQL('select vn.vstdate,vn.hn,concat(pt.pname,pt.fname," ",pt.lname) as ptname,pt.cid,vn.pttype,ptt.name, '+
'vn.pdx,icd.name,vn.income,ost.name ,k1.department,k2.department '+
'from vn_stat vn '+
'left outer join patient pt on pt.hn=vn.hn '+
'left outer join pttype ptt on ptt.pttype=vn.pttype '+
'left outer join icd101 icd on icd.code=vn.pdx '+
'left outer join ovst ovs on ovs.vn=vn.vn '+
'left outer join ovstost ost on ost.ovstost=ovs.ovstost '+
'left outer join kskdepartment k1 on k1.depcode = ovs.main_dep '+
'left outer join kskdepartment k2 on k2.depcode = ovs.last_dep '+
'where vn.vstdate between "'+ds1+'" and "'+ds2+'" '+
'and (k1.department = "'+suchat+'" or k2.department = "'+suchat+'")');
end;