• I can't see the purpose of the ORDER BY clause.  If you were to remove this from your select statement, you may find that you improve the performance.  It may also be the case that the outer loop has an ORDER BY clause that can also be removed.

    Profile the procedure to determine what indexes are being used on the tables.  Ensure that the indexes in use are the most efficient. You may be able to improve the performance yet again by creating covering indexes.

    Stephen Bailey