ลองเอา Script นี้ไปเรียกใช้เพื่อแก้ปัญหาครับ
var tc:tclientdataset;
begin
tc:=tclientdataset.create(nil);
tc.data:=hosxp_Getdataset('select * from medpay_ipd where med_plan_number < 1000');
while not tc.eof do
begin
tc.edit;
try
tc.fieldbyname('med_plan_number').asinteger:=
getsqldata('select med_plan_number from medplan_ipd where an = "'+
tc.fieldbyname('an').asstring+'"'+
' and icode="'+tc.fieldbyname('icode').asstring+'" '+
' and orderdate<="'+formatdatetime('yyyy-mm-dd',tc.fieldbyname('order_date').asdatetime)+'" ');
except
end;
tc.post;
setstatuslabel('Processing data '+inttostr(tc.recno)+' / '+inttostr(tc.recordcount));
tc.next;
end;
if tc.changecount>0 then
hosxp_updatedelta(tc.delta,'select * from medpay_ipd where med_plan_number < 1000');
tc.free;
showmessage('Done.');
end;