dbTalk Databases Forums  

Import Flat File Without Duplicates

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Import Flat File Without Duplicates in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jake_adl
 
Posts: n/a

Default Import Flat File Without Duplicates - 05-28-2006 , 06:47 PM






I have a flat file with customer information that looks like:

Name, Suburb, Postcode
John, Adelaide, 5000
Mary, Adelaide, 5000
Mark, Melbourne, 3000
Elizabeth, Sydney, 2000
George, Adelaide 5000
Henry, Melbourne, 3000

I need to add the Suburb and Postcode to a related table but it has a Unique
Index on it for Suburb and Postcode.

How can I extract only one instance of each Suburb|Postcode, ie:
Adelaide, 5000
Melbourne, 3000
Sydney, 2000

and insert those values into the Regions table before importing the customer
details into the Customer table?

Thank you

Reply With Quote
  #2  
Old   
JXStern
 
Posts: n/a

Default Re: Import Flat File Without Duplicates - 05-29-2006 , 02:00 PM






On Sun, 28 May 2006 16:47:01 -0700, Jake_adl
<Jakeadl (AT) discussions (DOT) microsoft.com> wrote:

Quote:
I have a flat file with customer information that looks like:

Name, Suburb, Postcode
John, Adelaide, 5000
Mary, Adelaide, 5000
Mark, Melbourne, 3000
Elizabeth, Sydney, 2000
George, Adelaide 5000
Henry, Melbourne, 3000

I need to add the Suburb and Postcode to a related table but it has a Unique
Index on it for Suburb and Postcode.

How can I extract only one instance of each Suburb|Postcode, ie:
Adelaide, 5000
Melbourne, 3000
Sydney, 2000

and insert those values into the Regions table before importing the customer
details into the Customer table?

You *could* write some fancy DTS transform code to parse each row and
build the suburb table on the fly,

but it's probaby better to (1) load the whole file into a staging
table, (2) run a query like "insert into regions_table select distinct
suburb, postcode from staging_table", (3) copy the data from the
staging table into the customer table with something like "insert into
customer select name, postcode_id from staging s inner join
regions_table r on s.suburb=r.suburb and s.postcode=r.postcode".

Have a nice day!

Josh



Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.