Looper, are you saying that you have multiple "John Smith"s with different employeeNos - or as RickD suggests, you somehow have duplicate employeeNos?A more typical problem is the former. If that is your case then you first need to decide what columns constitute a "duplicate" row. Let's assume for a minute that it is [FirstName] + [LastName]. Of course a large database is likely to have 2 different people with the same LastName and FirstName so that is probably not a good candidate key. But for the sake of argument if it was a good cadidate for a logical unique key and both firstname and lastname do not allow nulls - you could:THIS CODE IS UNTESTED - plus you don't want to assume that the same firstname+lastname is the same person.--first update employement to the max employeeid for each personupdate emp set emp.employeeid = d.MaxEmployeeIDfrom (--get dupe employeess select isNull(Firstname,'') + isNull(LastName,''), max(employeeid) as MaxEmployeeid from employee group by isNull(Firstname,'') + isNull(LastName,'') having count(*) > 1 ) as djoin employee e on emp.firstname = d.firstname and emp.lastname = d.lastnamejoin employment emp on emp.firstname = e.firstname and emp.lastname = e.lastname and emp.Employeeid < e.employeeID--get rid of the dupes from employeedelete efrom (--get dupe employeess select isNull(Firstname,'') + isNull(LastName,''), max(employeeid) as MaxEmployeeid from employee group by isNull(Firstname,'') + isNull(LastName,'') having count(*) > 1 ) as djoin employee e on e.firstname = d.firstname and e.lastname = d.lastname and e.Employeeid < d.MaxEmployeeID
Be One with the OptimizerTG