Sales order archiving errors 'There is already an object named AR_SO_History ....'

Problem

Running the archive utility for sales orders can error where a previous attempt to archive has failed or been interrupted.

Solution

SQL skills are required

A working knowledge of SQL Management Studio is required to complete this task.

The problem is caused by a failed/interrupted sales order archive run. What happens is that tables are created and used by the underlying stored procedure. If these tables do not get cleaned up by the stored procedure at the end (say, because it got interrupted or fell over for some reason), then next time it is run it won't be able to create it's tables (because they already exist).

The script is generic in that it will simply detect and delete any tables that are going to get in the way of the sales order archive.

DO NOT run this script while the archive process is happening.