How were you executing the script? Scheduled stored proc, trigger, etc.? I know that we've temporarily discontinued our use of SQL database triggers because they seem to deadlock process in 8.12/8.96. Before upgrading, we used triggers to archive our cost files (F4105, F3002). When we went live, processes that read these files (and there are oh so many) would timeout or deadlock, thereby blocking other processes (RF, UBEs, etc.,) until the system was virtually dead. We removed the triggers and wahla, no more problems. Similarly, we used to have a trigger on the submitted jobs file that would do something similar to what you're describing with moving jobs around when we hit a certain number of jobs at a wait status. It too has been removed until we can figure out what the problem is.
Francois