Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSIS Duplicate Record Removal Expand / Collapse
Author
Message
Posted Thursday, May 08, 2008 3:39 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 13, 2014 10:19 AM
Points: 20, Visits: 70
If anyone could help with the following I would greatly appreciate your help.

Basically I have a Data Flow Task.

I am moving data from one ole db source to another.

I would like to remove duplicate rows prior to being pushed in the the OLE Destination.

So my data might be something like this.

1 Employee1 Level 0
1 Employee1 Level 1
2 Employee2 Level 0
2 Employee2 Level 1
3 Employee3 Level 3
3 Employee3 Level 4

I want my output to be as follows:

1 Employee1 Level 0
2 Employee2 Level 0
3 Employee3 Level 3

Basically for each employee I if they appear twice i want to select the employee with the minimum level. I know this can be achieved using SQL however the volume of data in question makes this very difficult as doing a top, join, group by etc slow the system to a halt. I was hoping if i sorted my data in SSIS as it flow through the Dataflow that I could do something as follows :->

IF employee on this row = employee on previous row then discard this row.

If anyone nows how this can be achieved please let me know.

Thanking you in advance for any help you maybe able to provide.

Regards Niall




Post #496972
Posted Thursday, May 08, 2008 4:21 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, May 25, 2012 8:08 AM
Points: 496, Visits: 508
Have you concluded that fixing this using SQL would affect perofrmance? (like using group by).

Otherwise using SQL similar to following can get you the desired result:

select * from YOURTABLE t where t.level = (select min(level) from YOURTABLE group by name having name=t.name)
Post #496988
Posted Thursday, May 08, 2008 4:37 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 13, 2014 10:19 AM
Points: 20, Visits: 70
Unfortunately SQL is not the desired option. Normally I would prefer to go this
method however in this case it is not feasable.

Cheers anyways mate.
Post #496991
Posted Thursday, May 08, 2008 11:06 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 12, 2013 8:44 AM
Points: 1,073, Visits: 6,334
Since you mentioned using a sort, chaining together two Sort components in the Data Flow would work. This would only make sense if SSIS was running on a server different from the source database though, otherwise SSIS would just be competing for resources with SQL.

[OLEDB Source] --> [Sort Component 1] --> [Sort Component 2] --> [OLEDB Destination]

Sort Component 1: Sort by EmployeeID (ASC) and LevelID (DESC).

Sort Component 2: Sort by EmployeeID (ASC) only, passing through Level ID, and select "Remove rows with duplicate sort values" in the Sort Transformation Editor dialog.

I don't see any statement in BOL about which duplicate is retained, but it appears the last one read is copied to the output.
Post #497274
Posted Friday, May 09, 2008 2:12 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, March 13, 2014 10:19 AM
Points: 20, Visits: 70
Cheers. I actually ended up doing it in SQL using the RANK( ) function which worked quite well.

However the above looks a good solution and I will end up using it at some stage.

Cheers mate.
Post #497658
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse