J'ai écrit une requête pour supprimer les enregistrements en double d'une table
;WITH a as
(
SELECT Firstname,ROW_NUMBER() OVER(PARTITION by Firstname, empID ORDER BY Firstname)
AS duplicateRecCount
FROM dbo.tblEmployee
)
--Now Delete Duplicate Records
DELETE FROM tblEmployee
WHERE duplicateRecCount > 1
Mais je ne sais pas où je me suis trompé c'est dire
Nom de colonne non valide
duplicateRecCount
Est-ce que quelqu'un peut m'aider?
Vous devez référencer le CTE dans l'instruction delete ...
WITH a as
(
SELECT Firstname,ROW_NUMBER() OVER(PARTITION by Firstname, empID ORDER BY Firstname)
AS duplicateRecCount
FROM dbo.tblEmployee
)
--Now Delete Duplicate Records
DELETE FROM a
WHERE duplicateRecCount > 1
DELETE duplicates FROM
(SELECT ROW_NUMBER() OVER (PARTITION BY firstname, lastname, EMPNO, salary,dept ORDER BY empno) cnt
FROM tblEmp) duplicates
WHERE duplicates.Cnt > 1