Solved

Filter duplicate rows in SSIS data flow task

Posted on 2010-09-14
5
1,761 Views
Last Modified: 2012-05-10
Hi Experts,

   I am retrieving data from oracle and inserting into sql server.
   I have 2 tables in oracle called Person and Contacts.
   Person:
      Person_ID, Forename, Surname, Initials, Title, AddressId, TelNo1, TelNo2, Email1, Email2
   Contact:
        Forename, Surname, Initials, Title, AddressId, TelNo1, TelNo2, Email1, Email2
        
      In SSIS, DataFlow, I am retrieving data from 2 tables and UNION ALL and assigning uniqueID for PersonID(sequence number)
      
      If I have a row in Person table and 3 rows in contacts table, after UNION ALL I am getting 4 rows for a person.
      All contacts will be inserted to Telecom table and Person details will be inserted to People table.
      But in People table I want only 1 row to be inserted(no duplicates).
      
      If AddressID is different for the same person, its not called as duplicate. so all rows
      are inserted to People table.
      
      How can I do this in SSIS data flow task after UNION ALL and assigning unique PersonID?
      I mean tracking duplicate records and not inserting into People table.
      
      I can't do UNIQUE INDEX with NO_DUP_VAL as the PersonID is generating after UNION ALL
      and is assigned to each contact i.e added to Telecom table.
      
      So, I want to do some logic after UNION ALL.
      
      Any suggestion?
0
Comment
Question by:rajvja
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 33673432
Hi,

Can u use max(addressid)?
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 33673443
  1. Do you have to do a UNION ALL instead of a UNION?  (DO you know the difference between those two? ;-)
  2. If you have to use the UNION ALL, then you might want to insert that data into a staging table and then select distinct rows from the staging table.
Remember, SSIS lets you have multiple steps if you need them and it looks like you may need them. ;-)
 
0
 
LVL 11

Author Comment

by:rajvja
ID: 33673828
Hi,

 thanks for the replies. Even I used UNION I am getting the same records.
There is a column in Person table called PERSON_ID(it is unique per row) and I need to retrieve that column coz based on that column I am generate surrogate keys.

Any solution? I am really strucked.
0
 
LVL 22

Accepted Solution

by:
8080_Diver earned 500 total points
ID: 33673911
In that case, you will need to pull the data into a staging table and then determine how to identify the duplicates that you don't want.  Be sure to add an Identity column in the staging table so that you can distinguish between totally duplicate rows.
For instance, you could create a query that selects the MAX(PERSON_ID) based upon the rest of the columns and then use that to control which row you use to either move the data to your final destination table or simply as part of the process of selecting the data and generating the surrogate keys.
Hmmm, does the PERSON_ID already exist or are you generating it as part of this process?
0
 
LVL 11

Author Closing Comment

by:rajvja
ID: 33680771
thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question