Connecting Tech Pros Worldwide Help | Site Map

How best to update client table records with a dozen or so changed records from another table?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 05:21 AM
MLH
Guest
 
Posts: n/a
Default How best to update client table records with a dozen or so changed records from another table?

We have a table (tblClients) with several thousand records.
Because of organizational structure, changes to those records
are maintained in a separate database. Weekly, about a dozen
or so clients change phone numbers, addresses or something.
The table housing changed client data is tblChangedClients. It
is IDENTICAL to tblClients - except for the table name.

We have been taking the recs from tblChangedClients and
manually pasting the changes into tblClients. The common,
unique key field in both tables is [cSSN]. The tables contain
the usual info fields (name, addr, city, state, zip, etc...) as well
as the cSSN field. I have tblChangedClients attached to my
database in which tblClients is local. Can a query be used to
update the dozen rec's in tblClients that need updating. Or, do
I have to do the changes one-by-one using DAO?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


  #2  
Old November 13th, 2005, 05:21 AM
David Schofield
Guest
 
Posts: n/a
Default Re: How best to update client table records with a dozen or so changed records from another table?

On Tue, 14 Dec 2004 10:22:21 -0500, MLH <CRCI@NorthState.net> wrote:
[color=blue]
>We have a table (tblClients) with several thousand records.
>Because of organizational structure, changes to those records
>are maintained in a separate database. Weekly, about a dozen
>or so clients change phone numbers, addresses or something.
>The table housing changed client data is tblChangedClients. It
>is IDENTICAL to tblClients - except for the table name.
>
>We have been taking the recs from tblChangedClients and
>manually pasting the changes into tblClients. The common,
>unique key field in both tables is [cSSN]. The tables contain
>the usual info fields (name, addr, city, state, zip, etc...) as well
>as the cSSN field. I have tblChangedClients attached to my
>database in which tblClients is local. Can a query be used to
>update the dozen rec's in tblClients that need updating. Or, do
>I have to do the changes one-by-one using DAO?
>
>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>[/color]
Hi
You can certainly use queries, in general you need three:

delete clients who no longer appear (if this is required)
DELETE tblClients.*
FROM tblClients LEFT JOIN tblChangedClients ON tblClients.cSSN =
tblChangedClients.cSSN
WHERE tblChangedClients.cSSN Is Null

update fields xxx for clients which are in both tables
UPDATE tblClients INNER JOIN tblChangedClients ON tblClients.cSSN =
tblChangedClients.cSSN SET tblClients.xxx = tblChangedClients.xxx

insert new clients
INSERT INTO tblClients ( cSSN, xxx )
SELECT tblChangedClients.cSSN, tblChangedClients.xxx
FROM tblClients RIGHT JOIN tblChangedClients ON tblClients.cSSN =
tblChangedClients.cSSN
WHERE tblClients.cSSN Is Null

David
  #3  
Old November 13th, 2005, 05:21 AM
MLH
Guest
 
Posts: n/a
Default Re: How best to update client table records with a dozen or so changed records from another table?

Thanks, David...
All I need is to update clients that exist in both tables, so I'll
try your 2nd recommendation and let you know how it turns
out. I appreciate the reply!

<snip>
[color=blue][color=green]
>>[/color]
>Hi
>You can certainly use queries, in general you need three:
>
>delete clients who no longer appear (if this is required)
>DELETE tblClients.*
>FROM tblClients LEFT JOIN tblChangedClients ON tblClients.cSSN =
>tblChangedClients.cSSN
>WHERE tblChangedClients.cSSN Is Null
>
>update fields xxx for clients which are in both tables
>UPDATE tblClients INNER JOIN tblChangedClients ON tblClients.cSSN =
>tblChangedClients.cSSN SET tblClients.xxx = tblChangedClients.xxx
>
>insert new clients
>INSERT INTO tblClients ( cSSN, xxx )
>SELECT tblChangedClients.cSSN, tblChangedClients.xxx
>FROM tblClients RIGHT JOIN tblChangedClients ON tblClients.cSSN =
>tblChangedClients.cSSN
>WHERE tblClients.cSSN Is Null
>
>David[/color]

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.