Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Describe how to use linked server?

930


How to list all tables in the database using odbc_tables()?

977


What the different topologies in which replication can be configured?

1017


How to drop existing indexes in ms sql server?

1011


How to recompile stored procedure at run time?

1005


Explain Normalization and DE normalization

1052


Define inner join in sql server joins?

986


Explain about system stored procedure?

969


What happens if null values are involved in comparison operations?

902


explain extended properties

926


Write an SQL query to obtain the 2nd highest salary.

1018


What are the disadvantages of using the stored procedures?

1015


What structure can you implement for the database to speed up table reads?

1154


What are SSL and TSL protocols?

931


Explain transaction server isolation?

979