My table Salary
has this structure:
EmpId Salary
-------------
1 3000
2 4000
3 5000
4 5000
5 8000
6 2000
I am trying to do the delete duplicate record but it is failing with the below query:
BEGIN TRAN
WITH CTE_BASE AS
(
SELECT
(ROW_NUMBER() OVER (PARTITION BY SALARY ORDER BY SALARY DESC)) AS rownum
FROM
Salary
)
--SELECT ROWNUM FROM CTE_BASE
DELETE FROM CTE_BASE
WHERE ROWNUM > 1
ROLLBACK TRAN
I get this error:
Msg 156, Level 15, State 1, Line 21
Incorrect syntax near the keyword 'AS'
The commented out SELECT
statement works though.
Is the CTE not scoped to single delete?