May 16, 2006 at 1:08 am
HI have Data as bellow (Table Name is Contact)
ID | Name |
1 | Vijay |
1 | Vijay |
2 | Ajay |
2 | Ajay |
I want following Data
ID | Name |
1 | Vijay |
2 | Ajay |
Please Suggest a Query.
Vijay Soni
May 16, 2006 at 1:29 am
Tyr something like this....
Declare @id int,
@name varchar (50),
@cnt int
Declare getallrecords cursor local static For
Select count (1), id, name
from contact (nolock)
group by id, name having count(1)>1
Open getallrecords
Fetch next from getallrecords into @id,@name
--Cursor to check with all other records
While @@fetch_status=0
Begin
Set @cnt= @cnt-1
Set rowcount @cnt
-- Deleting the duplicate records. Observe that all fields are mentioned at the where condition
Delete from contact where id=@id and name=@name
Set rowcount 0
Fetch next from getallrecords into @cnt,@id,@name End
Close getallrecords
Deallocate getallrecords
Hope this helps...
Ford Fairlane
Rock and Roll Detective
May 16, 2006 at 8:59 am
If it doesn't help have a look on this link in the MS VKB:
http://support.microsoft.com/default.aspx?scid=kb;en-us;139444
regards,
Holger
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply