Subject How to Update when the val is a result set from a select
Author Car Toper
Disclamer: I am using Interbase 7.5

I have a table that has a SORT_ORDER field, I need to rebalance the
SORT_ORDER field, currently the values are 8, 16, 32, 63, 125, 250,
500, and 1000. I need to set them to 1000, 2000, ..., 8000.

My thought process is this:

1: use the gen_id to generate the 1000 thru 8000 in a select statement
(which does return the result set I expect):

SET GENERATOR SortGen TO 0;
SELECT gen_id(SortGen, 1000), UDA_AT_QUESTION_BOX_ID, SORT_ORDER
from UDA_AT_SECTION_QUESTION
WHERE UDA_AT_SECTION_ID = 5
ORDER BY SORT_ORDER;

2: Use that result set in the update to set the new SORT_ORDER value,
where the ID of the two match. Something like this:

SET GENERATOR SortGen TO 0;
update UDA_AT_SECTION_QUESTION
set SORT_ORDER = (
SELECT gen_id(SortGen, 1000) from UDA_AT_SECTION_QUESTION S2
WHERE UDA_AT_SECTION_ID = 5 AND UDA_AT_QUESTION_BOX_ID =
S2.UDA_AT_QUESTION_BOX_ID
ORDER BY SORT_ORDER
)
WHERE UDA_AT_SECTION_ID = 5;

When I run this update, the db complains about the inner select
statement, but according to the documentation it is possible to set
the val in an update to a valid SQL statement that returns only one
value.

What am I doing wrong here?