Home Forums SQL Server 2005 Administering Get rid of duplicate records in a table using SQL Server 2005 RE: Get rid of duplicate records in a table using SQL Server 2005

  • Hi There,

    Yes i do agree that this question has been revolving round and round but i would like to get help as well. I used to work on MS SQL Server 2000 and now using MS SQL Server 2005, I used to have 1 central table(tblModels) that has unique key on both "Manuf" and "ModelDes" that allow only unique records in and we're quering from that table on a daily basis. Now i have created the same table with same records and index key on both fields using MS SQL Server 2005.But when ever i try to append records that we receive daily into tblModels, if there are duplicates contained in that records, the whole transaction is rolled back and nothing get appended. How can i get rid of these?

    Example of Syntax:

    Insert into Server.DBName.dbo.tblModels (InvalidModelDescription,ManufacturerID)

    Select distinct RawModelDes,Manuf

    From tblPrepTemplate_SMS

    WHERE RawModelDes NOT IN

    (SELECT InvalidModelDescription

    FROM "Server".DBName.dbo.tblModels where ManufacturerID IS NULL)

    Select Count(*) as Count,InvalidModelDescription,ManufacturerID

    From dbo.lutModels

    Group by InvalidModelDescription,ManufacturerID

    Having Count(*)>1

    Order By InvalidModelDescription

    Error Msg " it complains about duplicate records on index key fields"