>If you're using SQL Server 2008 and up, you don't even need to use temp table for OUTPUT, you can perform one complex UPDATE command using its output as derived table in the UPDATE. I forgot the proper term for this at the moment, but I know where to search for it.
I wasn't sure if there was a way to update and delete in the same command. If that would be the case, I can get rid of the second duplicate CTE command to recreate all this.