MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IF statement in Triggers

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
drammo
Beginner


Joined: 13 Jan 2006
Posts: 20
Topics: 10

PostPosted: Wed Jan 18, 2006 8:59 am    Post subject: IF statement in Triggers Reply with quote

Does DB2 V8 for Z/OS allow IF statement inside a create trigger SQL? If so, what is the terminator for the statement? Is it "END IF" or "END-IF" or something else?

Thanks in anticipation.
Back to top
View user's profile Send private message
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Thu Jan 19, 2006 10:45 am    Post subject: Reply with quote

drammo,

I don't see why not. The terminator should be "END IF".

Regards,
Manas
_________________
There is no path to peace. Peace is the path.
- Mahatma Gandhi (1869-1948)
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
drammo
Beginner


Joined: 13 Jan 2006
Posts: 20
Topics: 10

PostPosted: Thu Jan 19, 2006 1:09 pm    Post subject: Reply with quote

Humor me, but I am running this query on z/os and end up with -199. QMF too points to error on line "END IF;". Please help.


Code:
CREATE TRIGGER TRG1
AFTER UPDATE ON TABLE1
REFERENCING OLD AS O NEW AS N
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
 IF N.COL2 = '01' THEN
  UPDATE TABLE2 A
     SET XCOL1 = XCOL9*0.80,
   WHERE A.XCOL3 = N.COL3;
 END IF;
END#

---------+---------+---------+---------+---------+---------+---------+--
DSNT408I SQLCODE = -199, ERROR: ILLEGAL USE OF KEYWORD IF, TOKEN
<END-OF-STATEMENT> WAS EXPECTED
DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNHPARS SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 0 0 0 -1 857 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'00000000' X'00000000' X'00000000' X'FFFFFFFF'
X'00000359' X'00000000' SQL DIAGNOSTIC INFORMATION
---------+---------+---------+---------+---------+---------+---------+--
Back to top
View user's profile Send private message
Bill Dennis
Advanced


Joined: 03 Dec 2002
Posts: 579
Topics: 1
Location: Iowa, USA

PostPosted: Thu Jan 19, 2006 1:57 pm    Post subject: Reply with quote

I am new to SQL, but how about dropping the IF and doing the test in WHERE

Code:
CREATE TRIGGER TRG1
AFTER UPDATE ON TABLE1
REFERENCING OLD AS O NEW AS N
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
  UPDATE TABLE2 A
     SET XCOL1 = XCOL9*0.80,
   WHERE A.XCOL3 = N.COL3 AND N.COL2 = '01';
END#

_________________
Regards,
Bill Dennis

Disclaimer: My comments on this foorum are my own and do not represent the opinions or suggestions of any other person or business entity.
Back to top
View user's profile Send private message
drammo
Beginner


Joined: 13 Jan 2006
Posts: 20
Topics: 10

PostPosted: Thu Jan 19, 2006 2:42 pm    Post subject: Reply with quote

Its a good suggestion Dennis, but my real SQL has ELSEIF conditions as well. To resolve the error, I reduced the query to bare minimum.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group