🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #758

Re: Update one table based on data in another

#758
From: Paul
Date: Tue, 26 Jun 2007 19:56
64 lines
3130 bytes
Actually Bill Im trying to sychronise all fields in the target table
and both tables have almost identical structure. But Im certain you
are right regards the performance issues. This is what I have been
previously been done..

1. Add an new records to the target customers table
2. Remove any orphans (customers that are no longer in  the source
customers table.)
3 Then update the data in the matching records thus..

//============================================
Fcount := CDS_IMPORTED.FieldCount -1;

While not  CDS_UPDATE_CUST.Eof do
      begin
           CurrAcc :=
CDS_UPDATE_CUST.FieldByname('ACCOUNT_REF').AsString;
           ThisAcc :=
CDS_IMPORTED.FieldByname('ACCOUNT_REF').AsString;
           if CurrAcc = ThisAcc then
           begin
                CDS_UPDATE_CUST.edit;
                for x:= 1 to Fcount do
                    CDS_UPDATE_CUST.Fields[x].AsVariant :=
CDS_IMPORTED.Fields[x].AsVariant;
                    
CDS_UPDATE_CUST.post;
           end;
      CDS_UPDATE_CUST.MoveBy(1);
      CDS_IMPORTED.MoveBy(1);
      end;

      if CDS_UPDATE_CUST.changecount > 0 then
         CDS_UPDATE_CUST.ApplyUpdates(-1);
//============================================

Of course I use an sql statement in both tables to sort on key fields
before running the above routine.

However, I will (as you suggest) just run the sql statement you
provided (which works great ;)) several times to update all fields.
Probably contruct the sql on the fly and programatically change the
field name.

Many thanks..

Paul.

On 25 Jun 2007 21:06:23 -0700, "Bill Todd" <no@no.com> wrote:

>Paul wrote:
>
>> Seems in many ways easier (although probably not as
>> efficient.)
>
>I doubt that it is easier since all you have to do is copy the line for
>the first field and change the field name for each successive field. It
>is certainly much less efficiant, cause much more network traffic and
>may cause performance problems if the number of users or the amount of
>netword traffic is high enough.

OS : Windows XP Service Pack 2
Delphi : 2005 Service Pack 3 Installed
CPU : AMD 3500+
Technical Details
Message-ID: <o3r283leioornf8hkkfnn17jiktrnmkc7d@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <bec083t4td4iqapnt5pu2sm66tp172oudu@4ax.com> <46804923$1@newsgroups.borland.com> <bov0839c1ajn1k0b8ercnip94med9g05g2@4ax.com> <468090bf$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,2270d561f33be473
X-Google-Attributes: gid114a0e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Paul <nospam@sdiespammersdie.com>
Newsgroups: borland.public.interbase.sql
Subject: Re: Update one table based on data in another
Date: Tue, 26 Jun 2007 20:56:18 +0100
Organization: None
Message-ID: <o3r283leioornf8hkkfnn17jiktrnmkc7d@4ax.com>
References: <bec083t4td4iqapnt5pu2sm66tp172oudu@4ax.com> <46804923$1@newsgroups.borland.com> <bov0839c1ajn1k0b8ercnip94med9g05g2@4ax.com> <468090bf$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.92/32.572
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 86.130.186.113
X-Trace: newsgroups.borland.com 1182887776 86.130.186.113 (26 Jun 2007 12:56:16 -0700)
Lines: 64
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail