• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Replace a list of item codes in .dbf file

I have a .dbf database table where I have a list of item codes in a column KITNO that need to be replaced with new codes.
I am using Borland Database Desktop v7 to make changes, using the sql editor.

to replace 1 itemcode at a time I would use

update kits
set kitno = "newcode"
where kitno = "oldcode"

What I would like to do though, is replace a whole list of "newcode" with corresponding "oldcode". There is far too many to want to do one at a time :)

Any suggestions on how to do this would be appreciated.
0
robd2007
Asked:
robd2007
  • 2
  • 2
1 Solution
 
twinsoftCommented:
Hi, if you have the new values in a table, why don't you use a while not eof loop to run an edit statement foreach record in the table ?
0
 
robd2007Author Commented:
Thanks for the reply, that sounds great as I have a table with new and old.

Could you give me a hand with the syntax? ;)
0
 
twinsoftCommented:
Procedure TForm1.UpdateDB;
begin
  with mytable do
    begin
     Open;
     First;
     while not eof do
       begin
         UpdateKits(FieldByName('newcode').AsString, FieldByName('oldcode').AsString);
        Next;
       end;
     Close;
    end;

procedure TForm1.UpdateKits(aNewCode, aOldCode: String);
begin
 here you update the kits table by running your SQL
 ...
end;
0
 
robd2007Author Commented:
Thank you very much, this saves me a lot of manual labour :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now