รู้สาเหตุและแก้ไขได้แล้ว
procedure GlobalOnCreate;
begin
GetDateRangeDialog(date1, date2);
ds1:= FormatDateTime('yyyy-mm-dd', date1);
ds2:= FormatDateTime('yyyy-mm-dd', date2);
ChangeReportSQL('select v.vstdate ,o.vsttime ,v.hn, concat(pname,fname," ",lname) as ptname , '+
'v.age_y , pt.name as pttype ,ov.icd10 , i.name as diag ,i.tname as thai_diag,d.licenseno,d.name as doctor, '+
'concat(p.addrpart," ËÁÙè ",p.moopart," ",t.full_name) as address , v.income '+
'from vn_stat v '+
'left outer join ovst o on v.vn = o.vn '+
'left outer join ovstdiag ov on v.vn = ov.vn '+
'left outer join patient p on v.hn = p.hn '+
'left outer join pttype pt on v.pttype = pt.pttype '+
'left outer join icd101 i on ov.icd10 = i.code '+
'left outer join doctor d on v.dx_doctor = d.code '+
'left outer join thaiaddress t on t.addressid=concat(p.chwpart,p.amppart,p.tmbpart) '+
'where o.main_dep like "600" '+ <--------------------- เปลี่ยนเป็น "%" เพราะว่ามีการวินิจฉัยที่ห้องตรวจอื่นที่ไม่ใช้คลินิกพิเศษครับ
'and v.vstdate between "'+ds1+'" and "'+ds2+'" '+
'and ((ov.icd10 in ("F03","F102","F105","F29","F33","F341","F38","F39")) or '+
'(ov.icd10 between "F103" and "F104") or '+
'(ov.icd10 between "F20" and "F209") or '+
'(ov.icd10 between "F41" and "F419") or '+
'(ov.icd10 between "F32" and "F329") or '+
'(ov.icd10 between "F48" and "F489") or '+
'(ov.icd10 between "F78" and "F789") or '+
'(ov.icd10 between "G40" and "G419") or '+
'(ov.icd10 between "Q90" and "Q909")) '+
' order by icd10 , vstdate , vsttime') ;
end;