ตามรูปคืออยากจะได้วันสุดท้ายที่ให้ยากับคนไข้อะครับ ต้องเขียนคำสั่งอย่างไรครับ
procedure GlobalOnDestroy;
begin
GetDateRangeDialog(date1,date2);
ds1:=FormatDateTime('yyyy-mm-dd',date1);
ds2:=FormatDateTime('yyyy-mm-dd',date2);
drug:= getpickuplist('select concat(name," ",strength," ",units) as drugname from drugitems order by drugname');
drug1:= getsqlstringdata('select icode from drugitems where concat(name," ",strength," ",units) = "'+drug+'"');
changereportsql('select op.hn,op.an,an.regdate,an.dchdate,i.name,concat(pt.pname,pt.fname," ",pt.lname)as ptname,op.rxdate,sum(op.qty) as total '+
' from opitemrece op '+
' left outer join patient pt on pt.hn=op.hn '+
' left outer join an_stat an on an.an=op.an '+
' left outer join icd101 i on i.code in (pdx,dx0,dx1,dx2,dx3,dx4,dx5) '+
' left outer join drugitems did on did.icode=op.icode '+
' where an.regdate between "'+ds1+'" and "'+ds2+'" '+
' and op.qty not like "0%" '+
' and op.an is not null '+
' and op.icode ="'+drug1+'" '+
' group by op.hn,op.an '+
' order by an.regdate ');
end;