Esql "select for update" and "order by"
Posted in 2017
In ESQL/C I need to do a statement like this ( I know that "order by" clause
is not allowed in a "select ... for update" )
SELECT FIRST 1 fd_foglio, fd_box_cod_soc, NVL(fd_id_subfoglio, 0)
FROM informix.foglioddt
WHEREfd_box_data_all = TO_CHAR(CURRENT YEAR TO DAY, '%iy%m%d') AND
fd_box_cod_soc = '*' order by fd_foglio DESC;
EXEC SQL
OPEN ifx_cursor_foglioddt_for_pending_crates;
EXEC SQL
FETCH ifx_cursor_foglioddt_for_pending_crates
INTO :fd_foglio, :fd_box_cod_soc, :local_fd_id_subfoglio;
in which I need a "order by" clause inside a "select for update" -I know that
isn't allowed - in order to use a cursor successively to increment the field
fd_id_subfogli (after I have used in other part of the code) with a statement
like:
UPDATE informix.foglioddt SET fd_id_subfoglio = :new_value WHERE
CURRENT OF ifx_cursor_foglioddt_for_pending_crates
How can I rewrite the previous code in order to select only the first ordered
record and update a field in it ?