|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, April 21, 2011 9:47 AM
Points: 16,
Visits: 47
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, March 02, 2012 2:50 AM
Points: 4,
Visits: 24
|
|
| This code does not give proper results. I tried to work on this but its really untested bad work by the developer.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, April 21, 2011 9:47 AM
Points: 16,
Visits: 47
|
|
| Ritesh what is it that is not working, can you let me know.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, October 21, 2008 1:36 AM
Points: 13,
Visits: 10
|
|
I think this is a much more efficient example for deleting duplicate rows using a single query and not having to resort to using Cursors:
http://dipakjpatel.blogspot.com/2007/08/delete-duplicate-rows-using-single.html
Regards
Nick
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 12:41 PM
Points: 113,
Visits: 56
|
|
don't need a temp table. don't need cursors.
you can remove dups in one statement.
cheers.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 8:23 AM
Points: 2,100,
Visits: 1,790
|
|
The code worked fine for me. There is more than one way to do this. So if you don't like this way try another but in terms of results this code works.
Francis
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, October 21, 2008 1:36 AM
Points: 13,
Visits: 10
|
|
I am sure the code works fine, however the article implied that this is one situation where you have to use cursors - which are very inefficient if you can do it alternatively in a single query:
>>This code works in SQL Server 2005 and above, because it uses the delete top (N) statement. Although using a cursor is not always a good idea but there are situations where we have to use it.
I am sure the cursor method with copying the data to a temporary table is satisfactory for small sets of data. I was surprised however to see it listed as a featured article in SQL Server Central's daily newsletter. When having to regularly run a query against e.g. 1m+ records that may involve several tables, it helps to know if there are more efficient methods. I thought it was worth pointing to a more efficient method that I came across recently as this is not a situation where we have to use cursors.
Regards
Nick
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, October 08, 2008 9:35 AM
Points: 1,
Visits: 2
|
|
A much simpler way to remove duplicates would be to use SELECT DISTINCT * from tableName
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, October 21, 2008 1:36 AM
Points: 13,
Visits: 10
|
|
SELECT DISTINCT * from tableName
While this gives you a list of records without the duplicates, it does not help much in deleting the duplicates. Additional code is still need to do something to remove the duplicates from the original table which this article addresses along with the other suggestions.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, January 02, 2009 11:25 AM
Points: 1,
Visits: 5
|
|
Thank you for sharing this. It was my introduction to cursors, and I was able to adapt it to keep my input table intact (by adding top(1) to another table, instead of deleting top @cnt).
Going forward, it does appear the common table expression approach linked by Nick has more promise.
All I wanted was something like 'Ignore row errors on insert'!
|
|
|
|