|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, July 26, 2010 9:06 AM
Points: 5,
Visits: 33
|
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, January 07, 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?
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 9:15 AM
Points: 14,
Visits: 35
|
|
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
|
|
|
|
|
Forum 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.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 9:15 AM
Points: 14,
Visits: 35
|
|
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
|
|
|
|
|
Forum 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.
|
|
|
|