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

Handle Duplicate Records Expand / Collapse
Author
Message
Posted Sunday, December 28, 2008 6:33 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, July 26, 2010 9:06 AM
Points: 5, Visits: 33
Comments posted to this topic are about the item Handle Duplicate Records
Post #626371
Posted Wednesday, January 7, 2009 7:51 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, January 7, 2013 2:28 PM
Points: 51, Visits: 158
I've found the easy way to remove duplicates is with the UNION statement:

select * into aTempTable
from SourceTable

UNION

select * from SourceTable

GO

truncate table SourceTable
insert into SourceTable
select * from aTempTable

GO

Does this work for you?
Post #631469
Posted Tuesday, April 7, 2009 10:57 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 25, 2013 1:20 PM
Points: 14, Visits: 46
Sorry I am still a newbie when it comes to programming like this...
What is the "@ID ..." signify. I figured out the ListOfFields but just can't figure out what the "@ID..." signifies.
Thank You
Ted
Post #692298
Posted Tuesday, April 7, 2009 1:36 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, July 26, 2010 9:06 AM
Points: 5, Visits: 33
No problem. Anything with an @ in front is a variable. @ID would hold a value for each row of the table that somehow uniquely identifies that row. So, the cursor has you looping through all the duplicate values. Each time it gets to "Fetch Next Into @ID", it puts the next value into the variable.

Then, the first time through the loop, it assigns that to @KeepID. And any subsequent loops, you would run all your logic to merge / move / delete the duplicate record.
Post #692459
Posted Tuesday, April 7, 2009 1:39 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 25, 2013 1:20 PM
Points: 14, Visits: 46
So the "..." after the "@ID" is not needed?
I do understand the basics of variables, but am still learning how to use them properly.
Thanks Ted
Post #692462
Posted Tuesday, April 7, 2009 2:03 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, July 26, 2010 9:06 AM
Points: 5, Visits: 33
No. Sorry, the example is just pseudo-code, you'll have to replace some stuff to make it actually work.

I put the '...' there in case you wanted to add more variables than just @ID ("FETCH NEXT INTO @ID, @Whatever, @Something). You could use the other variable in whatever processing you need to run, or if the primary key on that table is multiple columns you'd need to grab all of them just to delete.
Post #692496
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse