I looked at the blog entry on how to use the Batch function, focusing mostly on the Update section.
Most of my bulk update requirements are slightly different to the case shown in the blog, and I was wondering if there is some function in Unidac that will solve my problem? Or perhaps some clever SQL?
A typical scenario is that I want to update a single field in a table (eg Products) with the latest selling price value. ie a field might already have the value $5.00 in it. I want to increase that by 5%. ie update the value to NewValue = OldValue + (5/100 * OldValue)
Currently I simply have to loop through every record in a table, read in the old value, add the new data, then save the record back again.
ie
Code: Select all
with tblProducts do
while not EOF do
begin
OldSelling=FieldByName('SELL').AsFloat;
NewSelling:=OldSelling + (5/100*OldSelling);
if OldSelling<>NewSelling then
begin
edit;
FieldByName('SELL').AsFloat:=NewSelling;
post;
end;
next;
end;
I sometimes use the Script component with UPDATES ie
UPDATE PRODUCT SET SELL = SELL + (5/100 * SELL)
or something along those lines.