View Single Post

   
  #3 (permalink)  
Old 02-29-2008, 06:41 PM
Miks
 
Posts: n/a
Default Re: Identifying Duplicates in a table

I have tried, My soultion may not be 100% perfect, Corrections welcome.

CREATE TABLE [dbo].[test2] (
[Name] [char] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Age] [int] NOT NULL ,
[flag] [int] NULL ,
[flag1] [int] NULL
) ON [PRIMARY]
GO

Table Values

Alen 19 0 0
Alen 19 0 0
Aex 20 0 0

Code
-----

declare @name varchar(20), @age int, @counts int

declare cust cursor for
select count(1), Name, Age from test2 group by Name, Age having
count(Name) > 1

open cust fetch next from cust
into @counts, @name, @age

while @@fetch_status = 0

if(@counts) = 2
update test2 set flag = 1 where Name = @name and Age = @age

fetch next from cust into @counts, @name, @age

close cust
deallocate cust

Reply With Quote