ลองดูนะครับ
ผมเพิ่มตรวจสอบ an_stat ดูว่าลง pdx (diag หลัก) หรือยัง
Value := GetSQLIntegerData('select count(r.an) from ipt i '
+' left outer join ipdrent r on i.an=r.an '
+' left outer join an_stat a on i.an=a.an '
+' where i.dchdate between "'+date1+'" and "'+date2+'" and '
+' (r.return_date-i.dchdate) > 7 and r.rent_user="'+DBPipeline['rent_user']+'" '
+' and (r.return_date <>"" or r.return_date is not null) and rent_reason_id="'+reason2+'" '
+' and (a.pdx is not null or a.pdx <>"") '
+' group by r.rent_user');