Import Data dropping duplicates

Import Data dropping duplicates

Post by farlo_d.. » Fri, 18 Oct 2002 04:28:32



say I have a table (Name, Address, City, State, Zip) with a Unique
Index on (Address, City, State, Zip). Is there a way to do an

Insert Into Table1 Select * from Table2

which will only insert the ones that don't violate the unique
constraint.

the only thing I've run into is the statement quitting as soon as it
hits a violation. I'd like it to skip that row and move to the next
one.

Thanks

-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----

 
 
 

Import Data dropping duplicates

Post by oj » Fri, 18 Oct 2002 04:48:06


Insert Into Table1 Select * from Table2 t2
where not exists(select 1
from table1 t1
where t1.address=t2.address
and t1.city=t2.city
and t1.state=t2.state
and t1.zip=t2.zip)

--
-oj
http://www.rac4sql.net


Quote:> say I have a table (Name, Address, City, State, Zip) with a Unique
> Index on (Address, City, State, Zip). Is there a way to do an

> Insert Into Table1 Select * from Table2

> which will only insert the ones that don't violate the unique
> constraint.

> the only thing I've run into is the statement quitting as soon as it
> hits a violation. I'd like it to skip that row and move to the next
> one.

> Thanks

> -----------== Posted via Newsfeed.Com - Uncensored Usenet News
==----------
>    http://www.newsfeed.com       The #1 Newsgroup Service in the World!
> -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers

=-----

 
 
 

Import Data dropping duplicates

Post by Robert Carneg » Fri, 18 Oct 2002 19:07:17


If Table2 contains duplicates of its own rows, you could do

Insert Into Table1
Select MAX(Name), Address, City, State, Zip from Table2 t2
where not exists(select 1
from table1 t1
where t1.address=t2.address
and t1.city=t2.city
and t1.state=t2.state
and t1.zip=t2.zip)
group by address, city, state, zip


> Insert Into Table1 Select * from Table2 t2
> where not exists(select 1
> from table1 t1
> where t1.address=t2.address
> and t1.city=t2.city
> and t1.state=t2.state
> and t1.zip=t2.zip)

> --
> -oj
> http://www.rac4sql.net



> > say I have a table (Name, Address, City, State, Zip) with a Unique
> > Index on (Address, City, State, Zip). Is there a way to do an

> > Insert Into Table1 Select * from Table2

> > which will only insert the ones that don't violate the unique
> > constraint.

> > the only thing I've run into is the statement quitting as soon as it
> > hits a violation. I'd like it to skip that row and move to the next
> > one.

> > Thanks

> > -----------== Posted via Newsfeed.Com - Uncensored Usenet News
>  ==----------
> >    http://www.newsfeed.com       The #1 Newsgroup Service in the World!
> > -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers
> =-----

 
 
 

1. Import data from text file, then log and remove records with duplicate ID

First I am new to DTS.  I am working with it to import data from a text file
to a SQL database, which I got done.

The file is really simple, 3 fields: Name, Code and Number.

It's possible that multiple records will have the same "Number".  When this
happens, it's possible that the name & code is different for these records.

Here is what I want to do:
1) Log this somehow for the user to review
2) Only keep 1 record for each "Number".  I will just delete the other
records that have a duplicate "number".  So if 3 records have the same value
for "Number", I will keep the first one and delete the other two.

Using DTS in SQL 2000, what are some best practices for doing this?

What should I do to log the issue?  Should I create a log table or is it
possible & recommended to use SQL Server logs somehow?

What is the best way to delete the duplicate records?

Thanks
-Colin

2. XML Parsing error in SP3a

3. Need to import data and avoid duplicates

4. Mobile SQL Server Database

5. Importing data and skipping duplicate keys?

6. Best way to maintain db without duplicate keys

7. Creating Tables from Imported Data and not duplicating information

8. Lock Violation

9. avoid duplicate record when import data from Excel to Access table

10. Importing data and removing duplicates

11. Duplicate records in drop down box created dynamicaly

12. Procudure to check for duplicate and drop if exists

13. How do you drop duplicate rows