อันนี้โคตรครับ เขียนใน event
procedure GlobalOnCreate;
begin
GetDateRangeDialog(d1, d2);
ds1:=formatdatetime('yyyy-mm-dd',d1);
ds2:=formatdatetime('yyyy-mm-dd',d2);
h1:= InputQuery('รหัส สอ.','รหัส สอ.');
ChangeReportSQL('select distinct vn.hn,vn.vstdate,concat(pname,fname," ",lname) as fullname,concat(pt.addrpart," หมู่ ",pt.moopart," ต.",t3.name," อ.",t2.name," จ.",t1.name) as fulladdressname '+
' from vn_stat vn'+
' left outer join ovst o on o.hn = vn.hn'+
' left outer join patient pt on pt.hn = vn.hn'+
' left outer join thaiaddress t1 on t1.chwpart=pt.chwpart and t1.amppart="00" and t1.tmbpart="00" '+
' left outer join thaiaddress t2 on t2.chwpart=pt.chwpart and t2.amppart=pt.amppart and t2.tmbpart="00" '+
' left outer join thaiaddress t3 on t3.chwpart=pt.chwpart and t3.amppart=pt.amppart and t3.tmbpart=pt.tmbpart'+
' where vn.vstdate between "'+ds1+'" and "'+ds2+'" '+
' and vn.pdx between "E100" and "E149" '+
' and o.hospsub = "'+h1+'" '+
' group by vn.hn'+
' order by vn.vstdate');
end;