• The fact that the code works on some systems and not others indicates the code is likely sound but that there may be an environmental factor in play preventing success only in some situations. It could be a lot of things though, including code, for example blocking, poor hardware causing long delays, a trigger on one system not on some others, index fragmentation or out of date statistics could be causing the query to take longer to complete.

    When you are running the process you can check the activity of that query to see what resource it is waiting on and whether it is blocked or just taking a longer time than expected to complete. You could fire up Activity Monitor from SSMS or get a copy of sp_WhoIsActive, either way you can filter on your SPID to see what's happening when you run your process.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato