• Hi Piet

    Thanks for guiding me. I've didn't even know about CTE before I started this topic. I'm trying to learn it but its just out of my grasp at the moment.

    Could you do me a massive favour and convert your code to insert the output into a table. I've realised that I need to run this job out of hours :-

    WITH MyDupesRN AS

    (

    SELECT *

    , ROW_NUMBER() OVER (PARTITION BY SomeDate, NumValue ORDER BY SomeDate, NumValue) AS rn

    FROM #Test

    )

    SELECT SomeDate, NumValue, rn

    FROM MyDupesRN

    WHERE rn=1;

    Kind Regards

    James