first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

T-SQL Code: DELETEing Duplicates

-- This code is inspired by MS KB article Q139444 -- ("INF: How to Remove Duplicate Rows From a Table").

SELECT [date],host,[file],kbID INTO #uVals FROM tblKLog GROUP BY [date],host,[file],kbID HAVING COUNT(*) > 1

DELETE tblKLog FROM tblKLog , #uVals WHERE tblKLog.[date] = #uVals.[date] AND tblKLog.host = #uVals.host AND tblKLog.[file] = #uVals.[file]

INSERT INTO tblKLog SELECT [date],host,[file],kbID FROM #uVals

DROP TABLE #uVals

SELECT [date],host,[file],kbID FROM tblKLog GROUP BY [date],host,[file],kbID HAVING COUNT(*) > 1

mod date: 2001-04-08T01:40:52.000Z