ORDER BY vs. UPDATE
Posted in 1992
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
This is potentially a bonehead question, but I've been unable to answer
it with my available documentation, so...
(BTW, I'm using i4gl 1.1 on an HP 9000/550, in case it matters. It's
old stuff, but it's what I've got to live with....)
I've got a table with a ``priority'' column, and want to be able to
renumber the priorities. For example, if I've got priorities like
1
2
4
5
I want to run the table through my function and get
1
2
3
4
The obvious (to me) thing to do was declare a cursor whose select
statement orders the table by priority, and then simply update
the priority column sequentially in a foreach loop on the cursor.
So, I tried something like (semi-copying something my predecessor had
done, so just keep in mind that I'm not totally sure of what I'm doing
before you flame the stupid 4gl here :^) ):
define
pr_rec record like pr.*,
new_pr smallint
let new_pr = 1
declare c_priority cursor for
select * from pr into pr_rec
where priority is not null
order by priority
for update of priority
foreach c_priority
let pr_rec.priority = new_pr
update
set priority = pr_rec.priority
where current of c_priority
let new_pr = new_pr + 1
end foreach
Unfortunately, I find that I can't have an ``order by'' clause when I'm
going to update.
Is what I want possible? How do I update in a particular order? Do I
*need* to update in a particular order, or is there something I'm
missing?
Any help is appreciated. (And gentle help is *especially* appreciated,
since I'm a bit ignorant at this 4gl stuff.)
Geoff
--
Geoff Allen \\ A fanatic is one who can't change his
uunet!pmafire!geoff \\ mind and won't change the subject.
geoff@pmafire.inel.gov \\ -- Winston Churchill