Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Duplicate Records

Author  Topic 

matticusfinch
Starting Member

9 Posts

Posted - 2005-07-14 : 12:23:26
I have two tables in the same database, ARACCT and ARADDR2, that hold member information.
The linking field between these two is the ARCODE field, in ARACCT this is a primary key, while in ARADDR2, it is not, due to the ability to put in multiple addresses per member.
I need to delete duplicate addresses between these two tables, and have used this query to identify what these records are.

select b.arcode, b.saddr1, b.saddr2, b.scity, b.sstate from aracct a
inner join araddr2 b
on a.arcode = b.arcode
where a.arcode = b.arcode and a.addr1 = b.saddr1 and a.addr2 = b.saddr2 and a.city = b.scity
and a.state = b.sstate

The problem is, I can't use a delete from araddr2 where arcode
in(above query) to delete these records, as this would delete all of that arcode, regardless of the other fields.

Any suggestions on how to do what I need?

Matt

Kristen
Test

22859 Posts

Posted - 2005-07-14 : 12:31:44
What's the PK on araddr2 ?

Kristen
Go to Top of Page

matticusfinch
Starting Member

9 Posts

Posted - 2005-07-14 : 13:48:56
Well, there-in lies the kicker.
There is none. The developers of the system were not terribly fond of doing things in a fundamentally sound way.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-07-14 : 14:06:25
Hehehe. OK.

You say using a delete with "IN", would this do instead:

DELETE B
FROM aracct a
INNER JOIN araddr2 b
ON a.arcode = b.arcode
WHERE a.arcode = b.arcode
AND a.addr1 = b.saddr1
AND a.addr2 = b.saddr2
AND a.city = b.scity
AND a.state = b.sstate

Kristen
Go to Top of Page

matticusfinch
Starting Member

9 Posts

Posted - 2005-07-14 : 15:26:50
Works great....thanks!
Go to Top of Page
   

- Advertisement -