• The before image should have been

    WHILE @COUNTER < (SELECT COUNT(*) FROM ##TEMP_TABLE)