Unit Script;
Procedure Main;
var
i:integer;
ts:tstringlist;
ds1,ds2:string;
begin
getdaterange;
ds1:=formatdatetime('yyyy-mm-dd',date_result1);
ds2:=formatdatetime('yyyy-mm-dd',date_result2);
ts:=tstringlist.create;
fcds.close;
fcds.datarequest('select * from ovst where vstdate between "'+ds1+'" and "'+ds2+'" ');
fcds.open;
fcds.first;
i:=0;
while not fcds.eof do
begin
i:=i+1;
setprogressbar(i,fcds.recordcount);
fcds2.close;
fcds2.datarequest('select * from ovstdiag where vn="'+fcds.fieldbyname('vn').asstring+'"');
fcds2.open;
ts.clear;
fcds2.first;
while not fcds2.eof do
begin
if ts.indexof(fcds2.fieldbyname('icd10').asstring)=-1 then
begin
ts.add(fcds2.fieldbyname('icd10').asstring);
end else
begin
ShowDebugText('Found duplicate icd entry VN '+fcds.fieldbyname('vn').asstring+' '+
fcds2.fieldbyname('icd10').asstring);
try
getsqldata('EXEC delete from ovstdiag where ovst_diag_id = '+fcds2.fieldbyname('ovst_diag_id').asstring);
except end;
end;
fcds2.next;
end;
fcds2.close;
fcds.next;
end;
ts.free;
showmessage('Done.');
end;
end.