I am trying to update a record with a sub select and retrieve a "REQUESTID" from the sub select to allow this value to be used later in my stored procedure. For some reason I can not get this value. Does anyone have a solution? I am thinking I can maybe do a select (with fetch first 1 rows only) with an isolation level (not sure which one) to get a REQUESTID, then update it, then do the select again. But I would rather get the value from the sub select. Here is my proc:
CREATE PROCEDURE MYDBA.PROCEDURE2 ( )
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN
DECLARE SOMEREQUEST INT DEFAULT 0;
-- Declare cursor for returning select
DECLARE cursor1 CURSOR WITH RETURN FOR
SELECT REQUESTID, REQUESTFILE, REQUESTSTATUS
FROM MYTABLE
WHERE REQUESTID = SOMEREQUEST
FOR READ ONLY;
-- Find a single record with REQUESTSTATUS = 'N and update it.
UPDATE MYTABLE
SET REQUESTSTATUS = 'P'
WHERE (REQUESTID in
(SELECT RequestID as SOMEREQUEST FROM MYTABLE WHERE (REQUESTSTATUS = 'N')
FETCH FIRST 1 ROWS ONLY));
-- Cursor left open for client application
OPEN cursor1;
END P1