Pages

Search This Blog

Monday, July 19, 2010

[T-Sql] Deleting Duplicate Records

Deleting Duplciate Records on any specific crieteria


DECLARE @DATE AS VARCHAR(19)
SET @DATE=(SELECT CONVERT(VARCHAR(19),ISNULL(MAX(TIMEMODIFIED),'01/01/2000'),121) FROM ACDW.DBO.QB_SALESREP)

INSERT INTO QB_SALESREP SELECT * FROM QB_SALESREP_TEMP WHERE TIMEMODIFIED>@DATE

DELETE ACDW.DBO.QB_SALESREP
FROM ACDW.DBO.QB_SALESREP TSR INNER JOIN
(
SELECT LISTID,MIN(TIMEMODIFIED) TIMEMODIFIED
FROM ACDW.DBO.QB_SALESREP
GROUP BY LISTID
HAVING COUNT(*)>1
) DD ON TSR.LISTID=DD.LISTID AND TSR.TIMEMODIFIED=DD.TIMEMODIFIED

No comments: