Dynamic sql for taking distinct data into temp table then reload into original table

You could just delete the duplicates instead (keeping the "preferred" record, whichever that is [assuming that they are not identical duplicates, if they are then just keep "first one"])

I use ROW_NUMBER() OVER() for that job, with ORDER BY so that preferred record is first, and then delete all rows WHERE Row Number >= 2