Want To Delete Duplicate Records

  • HI have Data as bellow (Table Name is Contact)

    IDName
    1Vijay
    1Vijay
    2Ajay
    2Ajay

    I want following Data

    IDName
    1Vijay
    2Ajay

    Please Suggest a Query.

    Vijay Soni

  • 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

  • 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