• Glad it worked.

    Just as an additional check as it may also affect this (and other) queries, how many CPU's you got allocated to this VM and how many tempdb files do you have?

    And if more than 1 file (which you should have) are they all set the same size?

    In case you are willing to try out these variations may or not improve it.

    Delete l
    From ACSLog.dbo.AuditLog l
    where l.AuditLogID in (select ao.AuditLogID
            from #archive_output ao
            where exists (select top 1 1
                 from ACSLog_Archive.dbo.AuditLog b
                 where Ao.AuditLogID = B.AuditLogID
                )
            )

    Delete l
    From ACSLog.dbo.AuditLog l
    where l.AuditLogID in (select ao.AuditLogID
            from #archive_output ao
            )
    and exists (select top 1 1
        from ACSLog_Archive.dbo.AuditLog b
        where Ao.AuditLogID = B.AuditLogID
        )

    For these variations you will most likely need to create a index on archive_output