How to retrieve duplicate rows in a table?
How to delete the duplicate entries in a table?
Answer Posted / mohit d jethva
///////////Cursor for delete duplicate record in
table//////////
DECLARE @ID int
DECLARE @NAME NVARCHAR(50)
DECLARE @COUNT int
DECLARE CUR_DELETE CURSOR FOR
SELECT [ID],[NAME],COUNT([ID]) FROM [Example] GROUP BY [ID],
[NAME] HAVING COUNT([ID]) > 1
OPEN CUR_DELETE
FETCH NEXT FROM CUR_DELETE INTO @ID,@NAME,@COUNT
/* Loop through cursor for remaining ID */
WHILE @@FETCH_STATUS = 0
BEGIN
DELETE TOP(@COUNT -1) FROM [Example] WHERE ID = @ID
FETCH NEXT FROM CUR_DELETE INTO @ID,@NAME,@COUNT
END
CLOSE CUR_DELETE
DEALLOCATE CUR_DELETE
Mohit D Jethva
| Is This Answer Correct ? | 7 Yes | 4 No |
Post New Answer View All Answers
What is the difference between push and pull subscription? : sql server replication
Explain Geography datatype in SQL Server
How do I start sql server?
In case you have filters in your report, when filters will be applied in cached report instance?
I have a table Events Events containing cardno,time,id,name--each id has a cardno my requirement is every day each employee swipe the card several times i want to calculate first and last time of each card the output should be name 1 2 6 7 in out in out holiday holiday xxx 09:30 06:30 09:40 06:45 where 1,2...... are dates for example january 1,2, etc. 6 and 7 are saturday and sunday how it is posssible
Explain mixed authentication mode of sql server?
What are SSL and TSL protocols?
You want to use bids to deploy a report to a different server than the one you chose in the report wizard. How can you change the server url?
what are the steps you will take to improve performance of a poor performing query? : Sql server database administration
Explain triggers?
what is difference between NULL and ISNULL in SQL Server 2008?
How to concatenate two strings in SQL Server.
How do you drop an index?
You want to check the syntax of a complicated update sql statement without executing it. What command should you use?
Explain about system database?