Wednesday, July 7, 2010

Delete Duplicate Records

SET ROWCOUNT 1
DELETE tblcity
FROM tblcity a
WHERE (SELECT COUNT(*) FROM tblcity b WHERE b.city = a.city and b.countryid='c081') > 1
WHILE @@rowcount > 0
DELETE tblcity
FROM tblcity a
WHERE (SELECT COUNT(*) FROM tblcity b WHERE b.city = a.city and b.countryid='c081' ) > 1
SET ROWCOUNT 0

No comments: