DB2 Trigger

I'm trying to create a trigger to update one field off another within the same table.  Something is wrong with the syntax.
Can someone help?


CREATE TRIGGER CUST_TLO_APPT_FLAG
AFTER UPDATE OF DELIVERY_APPT_REQ ON TLORDER
REFERENCING NEW AS N OLD AS O
FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
  IF O.DELIVERY_APPT_REQ = 'False' and N.DELIVERY_APPT_REQ = 'True' THEN SET USER9 ='Y' ;
  END IF;
  IF O.DELIVERY_APPT_REQ = 'True' and N.DELIVERY_APPT_REQ = 'False' THEN SET USER9 ='' ;
  END IF;
END@

Open in new window

LVL 1
JDCamAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenDBACommented:
Hi JD,

I believe that you want a BEFORE trigger here.


Kent
JDCamAuthor Commented:
This is the error we are getting:
I don't understand as we are only using one table here.

-- Failure!!!
-- [IBM][CLI Driver][DB2/NT64] SQL0203N  A reference to column "USER9" is ambiguous.  LINE NUMBER=8.  SQLSTATE=42702
Kent OlsenDBACommented:
Ah.  That's an easy one.  :)

Both Old and New have a field called 'USER9'.  O.USER9 is valid, so is N.USER9.

The SET will have to set N.USER9 = ....


Kent

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JDCamAuthor Commented:
That worked.
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.