Skip to content
Advertisement

SQL execute block using update

I am trying to perform an execute block using an update. However I am getting an error.

The SQL shown here is similar to the real problem, but the update is much more complex. I need to use every declared cust_id into the update block.

EXECUTE BLOCK 

AS DECLARE VARIABLE CUSTOMER INT;

BEGIN
FOR
SELECT CUST_ID FROM CLIEN
 WHERE CUST_ID IN (1,2,3,4)
INTO :CUSTOMER

DO
BEGIN
UPDATE ORDERS
 SET STATUS='I'
WHERE CUST_ID=(SELECT CUST_ID
  FROM CUSTCONDITION
    WHERE CONDITION='OK' AND CUST_ID=:CUSTOMER)

DO BEGIN

END
END
END

How can I accomplish that?

Advertisement

Answer

you cannot use do begin after our update statement

EXECUTE BLOCK 

AS DECLARE VARIABLE CUSTOMER INT;

BEGIN
FOR
SELECT CUST_ID FROM CLIEN
 WHERE CUST_ID IN (1,2,3,4)
INTO :CUSTOMER

DO
BEGIN
UPDATE ORDERS
 SET STATUS='I'
WHERE CUST_ID=(SELECT CUST_ID
  FROM CUSTCONDITION
    WHERE CONDITION='OK' AND CUST_ID=:CUSTOMER);

END
END
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement