deleting duplicate records

K

KevinJ

Hello,
I have a table (table a) with a facility id field. I have an updated table
(table b) with some of the same facility id's. I want to append B to A and
replace any duplicates with those from B.
 
D

David Lloyd

Kevin:

One approach is to break the process up into two parts. In the first part,
update Table A with data from Table B where there is a matching facility ID.
For example:

UPDATE TEST_A INNER JOIN TEST_B ON TEST_A.ID = TEST_B.ID SET TEST_A.Field1 =
[Test_B].[Field1], TEST_A.Field2 = [Test_B].[Field2], TEST_A.Field3 =
[Test_B].[Field3];

The second part is to add those records from Table B that do not have a
current facility ID in Table A. For example,

INSERT INTO TEST_A
SELECT TEST_B.*
FROM TEST_A RIGHT JOIN TEST_B ON TEST_A.ID = TEST_B.ID
WHERE (((TEST_A.ID) Is Null));

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Hello,
I have a table (table a) with a facility id field. I have an updated table
(table b) with some of the same facility id's. I want to append B to A and
replace any duplicates with those from B.
 
Top