PROGRAM YINDEE;
var
tc,tc1:tclientdataset;
begin
tc:=tclientdataset.create(nil);
tc1:=tclientdataset.create(nil);
tc.data:=hosxp_getdataset('select * from clinicmember where next_app_date="1900-01-01" order by hn');
while not tc.eof do
begin
tc1.data:=hosxp_getdataset('select nextdate from oapp where hn="'+tc.fieldbyname('hn').asstring+'" and '+
'clinic="'+tc.fieldbyname('clinic').asstring+'" order by oapp_id desc limit 1');
tc.edit;
tc.fieldbyname('next_app_date').asstring:=tc1.fieldbyname('nextdate').asstring;
tc.post;
showdebugtext('HN = '+tc.fieldbyname('hn').asstring+' CLINIC = '+tc.fieldbyname('clinic').asstring+' >>>>>> '+' nextdate = '+
tc1.fieldbyname('nextdate').asstring);
tc.next;
end;
if tc.changecount>0 then
hosxp_updatedelta(tc.delta,'select * from clinicmember where next_app_date="1900-01-01" order by hn');
tc1.free;
tc.free;
showmessage('Process Done');
end.