Re: Resequencing a table
Posted in 1997
This code will not work as you can't do order by in a cursor that is for update. RTFM. You have to remove the "for update" and do the update inside the foreach loop using the primary key of the table. Of course you should prepare your update statement and execute it inside the foreach loop. That will increase the speed significantly. Also see my other responce for the SPL solution which is quite similar. ngall@stratis-caribbean.com (Nigel Gall) wrote: :Try this algorithm/code snippets: : : - Using 4GL, setup a cursor, row_curs, as follows: : declare row_curs cursor for : select stepno from tasks : order by stepno : for update : : - Later, in the function to update the stepno, use this code: : define new_step integer -- to allow for large values of stepno : ... : let new_step = 0 : foreach row_curs into dummy_step : let new_step = new_step + 10 : update tasks : set stepno = new_step : where current of row_curs : end foreach : :This presumes that you do not have duplicate stepno values in the :database. Sorry I don't have much experience with SPL. : :Happy coding. Nils.Myklebust@idg.no NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company The Informix FAQ is at http://www.iiug.org